Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous Cleanups #3178

Merged
merged 10 commits into from
Oct 26, 2022
12 changes: 8 additions & 4 deletions stl/inc/execution
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,9 @@ template <class _RanIt, class _Diff>
struct _Static_partition_range<_RanIt, _Diff, true> {
using _Target_diff = _Iter_diff_t<_RanIt>;
using _URanIt = _Unwrapped_t<const _RanIt&>;
using _Chunk_type = _Iterator_range<_URanIt>;

_URanIt _Start_at;
using _Chunk_type = _Iterator_range<_URanIt>;

_RanIt _Populate(const _Static_partition_team<_Diff>& _Team, _RanIt _First) {
// statically partition a random-access iterator range and return next(_First, _Team._Count)
Expand Down Expand Up @@ -866,8 +867,9 @@ template <class _FwdIt, class _Diff>
struct _Static_partition_range<_FwdIt, _Diff, false> {
using _Target_diff = _Iter_diff_t<_FwdIt>;
using _UFwdIt = _Unwrapped_t<const _FwdIt&>;
using _Chunk_type = _Iterator_range<_UFwdIt>;

_Parallel_vector<_UFwdIt> _Division_points;
using _Chunk_type = _Iterator_range<_UFwdIt>;

_FwdIt _Populate(const _Static_partition_team<_Diff>& _Team, _FwdIt _First) {
// statically partition a forward iterator range and return next(_First, _Team._Count)
Expand Down Expand Up @@ -949,8 +951,9 @@ struct _Static_partition_range_backward;
template <class _RanIt, class _Diff>
struct _Static_partition_range_backward<_RanIt, _Diff, true> {
using _Target_diff = _Iter_diff_t<_RanIt>;
using _Chunk_type = _Iterator_range<_Unwrapped_t<const _RanIt&>>;

_Unwrapped_t<const _RanIt&> _Start_at;
using _Chunk_type = _Iterator_range<_Unwrapped_t<const _RanIt&>>;

void _Populate(const _Static_partition_team<_Diff>& _Team, _RanIt _Last) {
// statically partition a random-access iterator range ending at _Last
Expand All @@ -969,8 +972,9 @@ struct _Static_partition_range_backward<_RanIt, _Diff, true> {
template <class _BidIt, class _Diff>
struct _Static_partition_range_backward<_BidIt, _Diff, false> {
using _Target_diff = _Iter_diff_t<_BidIt>;
using _Chunk_type = _Iterator_range<_Unwrapped_t<const _BidIt&>>;

_Parallel_vector<_Unwrapped_t<const _BidIt&>> _Division_points;
using _Chunk_type = _Iterator_range<_Unwrapped_t<const _BidIt&>>;

void _Populate(const _Static_partition_team<_Diff>& _Team, _BidIt _Last) {
// statically partition a bidirectional iterator range ending at _Last
Expand Down
66 changes: 20 additions & 46 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -2053,12 +2053,6 @@ namespace ranges {
template <class _Rng, class _Fn> // TRANSITION, LLVM-47414
concept _Can_const_transform = range<const _Rng> && regular_invocable<const _Fn&, range_reference_t<const _Rng>>;

#if _ITERATOR_DEBUG_LEVEL == 0
#define _NOEXCEPT_IDL0(...) noexcept(__VA_ARGS__)
#else
#define _NOEXCEPT_IDL0(...)
#endif // _ITERATOR_DEBUG_LEVEL == 0

_EXPORT_STD template <input_range _Vw, _Valid_movable_box_object _Fn>
requires view<_Vw>
&& regular_invocable<_Fn&, range_reference_t<_Vw>>
Expand Down Expand Up @@ -2204,39 +2198,19 @@ namespace ranges {
return _Tmp;
}

constexpr void _Verify_offset(const difference_type _Off) const
#if _ITERATOR_DEBUG_LEVEL != 0
constexpr void _Verify_offset(const difference_type _Off) const noexcept
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL == 0
(void) _Off;
#else // ^^^ _ITERATOR_DEBUG_LEVEL == 0 / _ITERATOR_DEBUG_LEVEL != 0 vvv
_STL_VERIFY(_Off == 0 || _Parent, "cannot seek value-initialized transform_view iterator");

if constexpr (_Offset_verifiable_v<iterator_t<_Base>>) {
_Current._Verify_offset(_Off);
} else {
if (_Off < 0) {
if constexpr (sized_sentinel_for<iterator_t<_Base>, iterator_t<_Base>>) {
_STL_VERIFY(_Off >= _RANGES begin(_Parent->_Range) - _Current,
"cannot seek transform_view iterator before begin");
}
} else if (_Off > 0) {
if constexpr (sized_sentinel_for<sentinel_t<_Base>, iterator_t<_Base>>) {
_STL_VERIFY(_Off <= _RANGES end(_Parent->_Range) - _Current,
"cannot seek transform_view iterator after end");
} else if constexpr (sized_sentinel_for<iterator_t<_Base>, iterator_t<_Base>>
&& sized_range<_Base>) {
const auto _Size = _RANGES distance(_Parent->_Range);
_STL_VERIFY(_Off <= _Size - (_Current - _RANGES begin(_Parent->_Range)),
"cannot seek transform_view iterator after end");
}
}
}
#endif // _ITERATOR_DEBUG_LEVEL == 0
}
#endif // _ITERATOR_DEBUG_LEVEL != 0

constexpr _Iterator& operator+=(const difference_type _Off)
_NOEXCEPT_IDL0(noexcept(_Current += _Off)) /* strengthened */
constexpr _Iterator& operator+=(const difference_type _Off) noexcept(
noexcept(_Current += _Off)) /* strengthened */
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
Expand All @@ -2245,19 +2219,20 @@ namespace ranges {
_Current += _Off;
return *this;
}
constexpr _Iterator& operator-=(const difference_type _Off)
_NOEXCEPT_IDL0(noexcept(_Current -= _Off)) /* strengthened */
constexpr _Iterator& operator-=(const difference_type _Off) noexcept(
noexcept(_Current -= _Off)) /* strengthened */
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
_STL_VERIFY(_Off != _Min_possible_v<difference_type>, "integer overflow");
_Verify_offset(-_Off);
#endif // _ITERATOR_DEBUG_LEVEL != 0
_Current -= _Off;
return *this;
}

_NODISCARD constexpr decltype(auto) operator[](const difference_type _Idx) const
_NOEXCEPT_IDL0(noexcept(_STD invoke(*_Parent->_Fun, _Current[_Idx]))) /* strengthened */
noexcept(noexcept(_STD invoke(*_Parent->_Fun, _Current[_Idx]))) /* strengthened */
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
Expand Down Expand Up @@ -2316,8 +2291,8 @@ namespace ranges {
return _Left._Current <=> _Right._Current;
}

_NODISCARD_FRIEND constexpr _Iterator operator+(_Iterator _It, difference_type _Off)
_NOEXCEPT_IDL0(noexcept(_It._Current += _Off)) /* strengthened */
_NODISCARD_FRIEND constexpr _Iterator operator+(_Iterator _It, const difference_type _Off) noexcept(
noexcept(_It._Current += _Off)) /* strengthened */
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
Expand All @@ -2326,8 +2301,8 @@ namespace ranges {
_It._Current += _Off;
return _It;
}
_NODISCARD_FRIEND constexpr _Iterator operator+(difference_type _Off, _Iterator _It)
_NOEXCEPT_IDL0(noexcept(_It._Current += _Off)) /* strengthened */
_NODISCARD_FRIEND constexpr _Iterator operator+(const difference_type _Off, _Iterator _It) noexcept(
noexcept(_It._Current += _Off)) /* strengthened */
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
Expand All @@ -2337,11 +2312,12 @@ namespace ranges {
return _It;
}

_NODISCARD_FRIEND constexpr _Iterator operator-(_Iterator _It, difference_type _Off)
_NOEXCEPT_IDL0(noexcept(_It._Current -= _Off)) /* strengthened */
_NODISCARD_FRIEND constexpr _Iterator operator-(_Iterator _It, const difference_type _Off) noexcept(
noexcept(_It._Current -= _Off)) /* strengthened */
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
_STL_VERIFY(_Off != _Min_possible_v<difference_type>, "integer overflow");
_It._Verify_offset(-_Off);
#endif // _ITERATOR_DEBUG_LEVEL != 0
_It._Current -= _Off;
Expand Down Expand Up @@ -2502,8 +2478,6 @@ namespace ranges {
}
};

#undef _NOEXCEPT_IDL0

template <class _Rng, class _Fn>
transform_view(_Rng&&, _Fn) -> transform_view<views::all_t<_Rng>, _Fn>;

Expand Down Expand Up @@ -5186,17 +5160,15 @@ namespace ranges {
return _Tmp;
}

#if _ITERATOR_DEBUG_LEVEL != 0
constexpr void _Verify_offset(const difference_type _Off) const
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
(void) _Off;
#else // ^^^ _ITERATOR_DEBUG_LEVEL == 0 / _ITERATOR_DEBUG_LEVEL != 0 vvv
if constexpr (_Offset_verifiable_v<iterator_t<_Base>>) {
_Current._Verify_offset(_Off);
}
#endif // _ITERATOR_DEBUG_LEVEL == 0
}
#endif // _ITERATOR_DEBUG_LEVEL != 0

constexpr _Iterator& operator+=(const difference_type _Off) noexcept(
noexcept(_Current += _Off)) /* strengthened */
Expand All @@ -5213,6 +5185,7 @@ namespace ranges {
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
_STL_VERIFY(_Off != _Min_possible_v<difference_type>, "integer overflow");
_Verify_offset(-_Off);
#endif // _ITERATOR_DEBUG_LEVEL != 0
_Current -= _Off;
Expand Down Expand Up @@ -5313,6 +5286,7 @@ namespace ranges {
requires random_access_range<_Base>
{
#if _ITERATOR_DEBUG_LEVEL != 0
_STL_VERIFY(_Off != _Min_possible_v<difference_type>, "integer overflow");
_It._Verify_offset(-_Off);
#endif // _ITERATOR_DEBUG_LEVEL != 0
auto _Copy = _It;
Expand Down
1 change: 1 addition & 0 deletions stl/inc/span
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct _Span_iterator {
}

constexpr _Span_iterator& operator-=(const difference_type _Off) noexcept {
_STL_VERIFY(_Off != _Min_possible_v<difference_type>, "integer overflow");
_Verify_offset(-_Off);
_Myptr -= _Off;
return *this;
Expand Down
40 changes: 20 additions & 20 deletions stl/inc/system_error
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ _EXPORT_STD _NODISCARD const error_category& system_category() noexcept;

_EXPORT_STD class __declspec(novtable) error_category { // categorize an error
public:
#ifndef _M_CEE_PURE
#ifdef _M_CEE_PURE
/* constexpr */ error_category() noexcept { // TRANSITION, ABI
_Addr = reinterpret_cast<uintptr_t>(this);
}
#else // ^^^ defined(_M_CEE_PURE) / !defined(_M_CEE_PURE) vvv
#pragma warning(push)
#pragma warning(disable : 4355) // 'this': used in base member initializer list
constexpr error_category() noexcept : _Addr(this) {}
#pragma warning(pop)
#else // ^^^ !defined(_M_CEE_PURE) / defined(_M_CEE_PURE) vvv
/* constexpr */ error_category() noexcept { // TRANSITION, ABI
_Addr = reinterpret_cast<uintptr_t>(this);
}
#endif // ^^^ defined(_M_CEE_PURE) ^^^
#endif // ^^^ !defined(_M_CEE_PURE) ^^^

_CONSTEXPR20 virtual ~error_category() noexcept = default;

Expand All @@ -91,11 +91,11 @@ public:
_NODISCARD virtual bool equivalent(const error_code& _Code, int _Errval) const noexcept;

_NODISCARD bool operator==(const error_category& _Right) const noexcept {
#ifndef _M_CEE_PURE
return _Bit_cast<uintptr_t>(_Addr) == _Bit_cast<uintptr_t>(_Right._Addr);
#else // ^^^ !defined(_M_CEE_PURE) / defined(_M_CEE_PURE) vvv
#ifdef _M_CEE_PURE
return _Addr == _Right._Addr;
#endif // ^^^ defined(_M_CEE_PURE) ^^^
#else // ^^^ defined(_M_CEE_PURE) / !defined(_M_CEE_PURE) vvv
return _Bit_cast<uintptr_t>(_Addr) == _Bit_cast<uintptr_t>(_Right._Addr);
#endif // ^^^ !defined(_M_CEE_PURE) ^^^
}

#if !_HAS_CXX20
Expand All @@ -110,19 +110,21 @@ public:
}
#else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv
_NODISCARD bool operator<(const error_category& _Right) const noexcept {
#ifndef _M_CEE_PURE
return _Bit_cast<uintptr_t>(_Addr) < _Bit_cast<uintptr_t>(_Right._Addr);
#else // ^^^ !defined(_M_CEE_PURE) / defined(_M_CEE_PURE) vvv
#ifdef _M_CEE_PURE
return _Addr < _Right._Addr;
#endif // ^^^ defined(_M_CEE_PURE) ^^^
#else // ^^^ defined(_M_CEE_PURE) / !defined(_M_CEE_PURE) vvv
return _Bit_cast<uintptr_t>(_Addr) < _Bit_cast<uintptr_t>(_Right._Addr);
#endif // ^^^ !defined(_M_CEE_PURE) ^^^
}
#endif // ^^^ !defined(__cpp_lib_concepts) ^^^

error_category(const error_category&) = delete;
error_category& operator=(const error_category&) = delete;

protected:
#ifndef _M_CEE_PURE
#ifdef _M_CEE_PURE
uintptr_t _Addr;
#else // ^^^ defined(_M_CEE_PURE) / !defined(_M_CEE_PURE) vvv
union _Addr_storage {
private:
uintptr_t _Num;
Expand All @@ -132,13 +134,11 @@ protected:
constexpr explicit _Addr_storage(const uintptr_t _Addr_num) noexcept : _Num(_Addr_num) {}
constexpr explicit _Addr_storage(error_category* const _Addr_ptr) noexcept : _Ptr(_Addr_ptr) {}
};
static_assert(sizeof(_Addr_storage) == sizeof(uintptr_t) && alignof(_Addr_storage) == alignof(uintptr_t),
"Unsupported platform");
_STL_INTERNAL_STATIC_ASSERT(sizeof(_Addr_storage) == sizeof(uintptr_t));
_STL_INTERNAL_STATIC_ASSERT(alignof(_Addr_storage) == alignof(uintptr_t));

_Addr_storage _Addr;
#else // ^^^ !defined(_M_CEE_PURE) / defined(_M_CEE_PURE) vvv
uintptr_t _Addr;
#endif // ^^^ defined(_M_CEE_PURE) ^^^
#endif // ^^^ !defined(_M_CEE_PURE) ^^^

constexpr explicit error_category(const uintptr_t _Addr_) noexcept : _Addr(_Addr_) {}

Expand Down
10 changes: 5 additions & 5 deletions stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -2648,13 +2648,13 @@ public:
#if _HAS_CXX23
constexpr basic_string(basic_string&& _Right, const size_type _Roff, const _Alloc& _Al = _Alloc())
: _Mypair(_One_then_variadic_args_t{}, _Al) { // construct from _Right [_Roff, <end>), potentially move
_Move_construct_from_substr(_Right, _Roff, npos, _Al);
_Move_construct_from_substr(_Right, _Roff, npos);
}

constexpr basic_string(
basic_string&& _Right, const size_type _Roff, const size_type _Count, const _Alloc& _Al = _Alloc())
: _Mypair(_One_then_variadic_args_t{}, _Al) { // construct from _Right [_Roff, _Roff + _Count), potentially move
_Move_construct_from_substr(_Right, _Roff, _Count, _Al);
_Move_construct_from_substr(_Right, _Roff, _Count);
}
#endif // _HAS_CXX23

Expand Down Expand Up @@ -3195,20 +3195,20 @@ private:
}

#if _HAS_CXX23
constexpr void _Move_construct_from_substr(
basic_string& _Right, const size_type _Roff, const size_type _Size_max, const _Alloc& _Al) {
constexpr void _Move_construct_from_substr(basic_string& _Right, const size_type _Roff, const size_type _Size_max) {
auto& _Right_data = _Right._Mypair._Myval2;
_Right_data._Check_offset(_Roff);

const auto _Result_size = _Right_data._Clamp_suffix_size(_Roff, _Size_max);
const auto _Right_ptr = _Right_data._Myptr();
auto& _Al = _Getal();
if (_Allocators_equal(_Al, _Right._Getal()) && _Result_size >= _BUF_SIZE) {
if (_Roff != 0) {
_Traits::move(_Right_ptr, _Right_ptr + _Roff, _Result_size);
}
_Right._Eos(_Result_size);

_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al));
_Take_contents(_Right);
} else {
_Construct<_Construct_strategy::_From_ptr>(_Right_ptr + _Roff, _Result_size);
Expand Down
7 changes: 4 additions & 3 deletions tests/std/tests/P0896R4_views_transform_death/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cassert>
#include <cstddef>
#include <ranges>
#include <span>
#include <vector>

#include <test_death.hpp>
Expand All @@ -14,7 +15,7 @@ using namespace std;
static int some_ints[] = {0, 1, 2, 3};

[[maybe_unused]] constexpr auto lambda = [x = 42](int) { return x == 42; };
using TV = decltype(ranges::transform_view{some_ints, lambda});
using TV = decltype(ranges::transform_view{span{some_ints}, lambda});

void test_constructor_wrong_range() {
vector<int> vec0{0, 1, 2, 3};
Expand Down Expand Up @@ -42,8 +43,8 @@ void test_operator_preincrement_value_initialized_iterator() {
}

void test_operator_preincrement_after_end() {
TV r{some_ints, lambda};
ranges::iterator_t<TV> i = ranges::next(r.begin(), r.end());
ranges::transform_view r{span{some_ints}, lambda};
auto i = ranges::next(r.begin(), r.end());
++i; // cannot increment transform_view iterator past end
}
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
7 changes: 3 additions & 4 deletions tests/std/tests/P2278R4_basic_const_iterator/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

using namespace std;

template <typename T>
template <class T>
concept Pointer = is_pointer_v<T>;

template <typename It>
template <class It>
concept HasPeek = requires(const It& iter) {
{ iter.peek() } -> Pointer;
requires convertible_to<decltype(iter.peek()), const iter_value_t<It>*>;
{ iter.peek() } -> convertible_to<const iter_value_t<It>*>;
};

static_assert(!HasPeek<int*>);
Expand Down Expand Up @@ -95,7 +95,6 @@ constexpr void test_one(It iter) {
assert(citer == iter);
assert(*citer == *iter);


if constexpr (bidirectional_iterator<It>) {
{ // Validate basic_const_iterator::operator--()
same_as<ConstIt&> decltype(auto) citer2 = --citer;
Expand Down
Loading