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

Unwrappable iter/sent pairs! #3024

Merged
merged 24 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b0b6698
wip; start working on unwrappable iter/sent pairs
strega-nil Aug 10, 2022
0f9d71c
perhaps this will make Casey happier?
strega-nil Aug 11, 2022
a0b4362
bug fixin plus tests
strega-nil Aug 11, 2022
eb70bf1
I like _Unwrapped_sentinel_for
strega-nil Aug 11, 2022
7d7eccd
oops forgot some casey crs
strega-nil Aug 11, 2022
b39e464
fix the colummmns
strega-nil Aug 18, 2022
e62d530
(* cries in fixing mechanical bugs *)
strega-nil Aug 18, 2022
349aed4
Merge remote-tracking branch 'upstream/main' into strega-nil/unwrappi…
strega-nil Aug 18, 2022
146049c
clang-format off makes me sad
strega-nil Aug 18, 2022
6dfeda8
Merge remote-tracking branch 'upstream/main' into strega-nil/unwrappi…
strega-nil Aug 18, 2022
b8bd9d1
merge _Is_nothrow_unwrappable_v and _Nothrow_unwrappable
strega-nil Aug 18, 2022
3b22fac
bug fixes
strega-nil Aug 19, 2022
f4b38c0
woot, found a buuuug (and write tests)
strega-nil Aug 19, 2022
4486695
fix compiler running out of heap
strega-nil Aug 19, 2022
e067c13
erp
strega-nil Aug 19, 2022
0fc1e53
Stephan CRs
strega-nil Aug 20, 2022
04adb8e
Casey CRs
strega-nil Aug 22, 2022
781be21
Casey CRs
strega-nil Aug 23, 2022
073b931
oops, fix the tests
strega-nil Aug 23, 2022
f9df39c
blagh
strega-nil Aug 23, 2022
96ebeaa
remove a mistaken clang-format off
strega-nil Aug 23, 2022
b4dbfab
Merge remote-tracking branch 'upstream/main' into strega-nil/unwrappi…
strega-nil Aug 29, 2022
e3b89ae
Stephan CRs
strega-nil Aug 30, 2022
8063bd8
Last changes for code review feedback.
StephanTLavavej Aug 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
470 changes: 245 additions & 225 deletions stl/inc/algorithm

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ namespace filesystem {
}
template <class _Iter2 = _Base_iter, enable_if_t<_Unwrappable_v<_Iter2>, int> = 0>
_NODISCARD _Path_iterator<_Unwrapped_t<_Iter2>> _Unwrapped() && noexcept {
_STL_INTERNAL_STATIC_ASSERT(_Is_nothrow_unwrappable_v<_Iter2>);
_STL_INTERNAL_STATIC_ASSERT(_Has_nothrow_unwrapped<_Iter2>);
return {_Position._Unwrapped(), _STD move(_Element), _Mypath};
}

Expand Down
35 changes: 18 additions & 17 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ namespace ranges {
// clang-format on
_Adl_verify_range(_First1, _Last1);
_Adl_verify_range(_First2, _Last2);
auto _UResult =
_Uninitialized_copy_unchecked(_Get_unwrapped(_STD move(_First1)), _Get_unwrapped(_STD move(_Last1)),
_Get_unwrapped(_STD move(_First2)), _Get_unwrapped(_STD move(_Last2)));
auto _UResult = _Uninitialized_copy_unchecked(_Unwrap_iter<_Se>(_STD move(_First1)),
_Unwrap_sent<_It>(_STD move(_Last1)), _Unwrap_iter<_OSe>(_STD move(_First2)),
_Unwrap_sent<_Out>(_STD move(_Last2)));

_Seek_wrapped(_First1, _STD move(_UResult.in));
_Seek_wrapped(_First2, _STD move(_UResult.out));
Expand All @@ -60,7 +60,7 @@ namespace ranges {
// clang-format on
auto _First1 = _RANGES begin(_Range1);
auto _UResult = _Uninitialized_copy_unchecked(
_Get_unwrapped(_STD move(_First1)), _Uend(_Range1), _Ubegin(_Range2), _Uend(_Range2));
_Unwrap_range_iter<_Rng1>(_STD move(_First1)), _Uend(_Range1), _Ubegin(_Range2), _Uend(_Range2));

_Seek_wrapped(_First1, _STD move(_UResult.in));
return {_STD move(_First1), _Rewrap_iterator(_Range2, _STD move(_UResult.out))};
Expand Down Expand Up @@ -154,8 +154,8 @@ namespace ranges {

_Adl_verify_range(_First2, _Last2);
auto _IFirst = _Get_unwrapped_n(_STD move(_First1), _Count);
auto _OFirst = _Get_unwrapped(_STD move(_First2));
auto _OLast = _Get_unwrapped(_STD move(_Last2));
auto _OFirst = _Unwrap_iter<_OSe>(_STD move(_First2));
auto _OLast = _Unwrap_sent<_Out>(_STD move(_Last2));
if constexpr (_Iter_copy_cat<_It, _Out>::_Bitcopy_constructible
&& _Sized_or_unreachable_sentinel_for<_OSe, _Out>) {
if constexpr (sized_sentinel_for<_OSe, _Out>) {
Expand Down Expand Up @@ -214,9 +214,9 @@ namespace ranges {
// clang-format on
_Adl_verify_range(_First1, _Last1);
_Adl_verify_range(_First2, _Last2);
auto _UResult = _RANGES _Uninitialized_move_unchecked(_Get_unwrapped(_STD move(_First1)),
_Get_unwrapped(_STD move(_Last1)), _Get_unwrapped(_STD move(_First2)),
_Get_unwrapped(_STD move(_Last2)));
auto _UResult = _RANGES _Uninitialized_move_unchecked(_Unwrap_iter<_Se>(_STD move(_First1)),
_Unwrap_sent<_It>(_STD move(_Last1)), _Unwrap_iter<_OSe>(_STD move(_First2)),
_Unwrap_sent<_Out>(_STD move(_Last2)));

_Seek_wrapped(_First1, _STD move(_UResult.in));
_Seek_wrapped(_First2, _STD move(_UResult.out));
Expand All @@ -231,7 +231,7 @@ namespace ranges {
// clang-format on
auto _First1 = _RANGES begin(_Range1);
auto _UResult = _RANGES _Uninitialized_move_unchecked(
_Get_unwrapped(_STD move(_First1)), _Uend(_Range1), _Ubegin(_Range2), _Uend(_Range2));
_Unwrap_range_iter<_Rng1>(_STD move(_First1)), _Uend(_Range1), _Ubegin(_Range2), _Uend(_Range2));

_Seek_wrapped(_First1, _STD move(_UResult.in));
return {_STD move(_First1), _Rewrap_iterator(_Range2, _STD move(_UResult.out))};
Expand Down Expand Up @@ -293,8 +293,8 @@ namespace ranges {

_Adl_verify_range(_First2, _Last2);
auto _IFirst = _Get_unwrapped_n(_STD move(_First1), _Count);
auto _OFirst = _Get_unwrapped(_STD move(_First2));
const auto _OLast = _Get_unwrapped(_STD move(_Last2));
auto _OFirst = _Unwrap_iter<_OSe>(_STD move(_First2));
const auto _OLast = _Unwrap_sent<_Out>(_STD move(_Last2));
if constexpr (_Iter_move_cat<_It, _Out>::_Bitcopy_constructible
&& _Sized_or_unreachable_sentinel_for<_OSe, _Out>) {
if constexpr (sized_sentinel_for<_OSe, _Out>) {
Expand Down Expand Up @@ -336,7 +336,7 @@ namespace ranges {
// clang-format on
_Adl_verify_range(_First, _Last);
auto _UResult = _Uninitialized_fill_unchecked(
_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last)), _Val);
_Unwrap_iter<_Se>(_STD move(_First)), _Unwrap_sent<_It>(_STD move(_Last)), _Val);

_Seek_wrapped(_First, _STD move(_UResult));
return _First;
Expand Down Expand Up @@ -542,7 +542,7 @@ namespace ranges {
// clang-format on
_Adl_verify_range(_First, _Last);
_Seek_wrapped(_First,
_RANGES _Destroy_unchecked(_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last))));
_RANGES _Destroy_unchecked(_Unwrap_iter<_Se>(_STD move(_First)), _Unwrap_sent<_It>(_STD move(_Last))));
return _First;
}

Expand All @@ -552,7 +552,8 @@ namespace ranges {
constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range) const noexcept {
// clang-format on
auto _First = _RANGES begin(_Range);
_Seek_wrapped(_First, _RANGES _Destroy_unchecked(_Get_unwrapped(_STD move(_First)), _Uend(_Range)));
_Seek_wrapped(
_First, _RANGES _Destroy_unchecked(_Unwrap_range_iter<_Rng>(_STD move(_First)), _Uend(_Range)));
return _First;
}
};
Expand Down Expand Up @@ -647,7 +648,7 @@ namespace ranges {
// clang-format on
_Adl_verify_range(_First, _Last);
auto _UResult = _Uninitialized_default_construct_unchecked(
_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last)));
_Unwrap_iter<_Se>(_STD move(_First)), _Unwrap_sent<_It>(_STD move(_Last)));

_Seek_wrapped(_First, _STD move(_UResult));
return _First;
Expand Down Expand Up @@ -782,7 +783,7 @@ namespace ranges {
// clang-format on
_Adl_verify_range(_First, _Last);
auto _UResult = _Uninitialized_value_construct_unchecked(
_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last)));
_Unwrap_iter<_Se>(_STD move(_First)), _Unwrap_sent<_It>(_STD move(_Last)));

_Seek_wrapped(_First, _STD move(_UResult));
return _First;
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/numeric
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,14 @@ namespace ranges {
constexpr iota_result<_It, _Ty> operator()(_It _First, _Se _Last, _Ty _Val) const {
_Adl_verify_range(_First, _Last);
_Seek_wrapped(
_First, _Iota_impl(_Get_unwrapped(_STD move(_First)), _Get_unwrapped(_STD move(_Last)), _Val));
_First, _Iota_impl(_Unwrap_iter<_Se>(_STD move(_First)), _Unwrap_sent<_It>(_STD move(_Last)), _Val));
return {_STD move(_First), _STD move(_Val)};
}

template <weakly_incrementable _Ty, output_range<const _Ty&> _Rng>
constexpr iota_result<borrowed_iterator_t<_Rng>, _Ty> operator()(_Rng&& _Range, _Ty _Val) const {
auto _First = _RANGES begin(_Range);
_Seek_wrapped(_First, _Iota_impl(_Get_unwrapped(_STD move(_First)), _Uend(_Range), _Val));
_Seek_wrapped(_First, _Iota_impl(_Unwrap_range_iter<_Rng>(_STD move(_First)), _Uend(_Range), _Val));
return {_STD move(_First), _STD move(_Val)};
}

Expand Down
24 changes: 12 additions & 12 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -2503,17 +2503,17 @@ namespace ranges {

// clang-format off
_NODISCARD constexpr auto _Unwrapped() const&
noexcept(noexcept(_Sentinel<_Const, false>{_Get_unwrapped(_Last)}))
requires _Wrapped && _Unwrappable_v<const iterator_t<_Base_t>&> {
noexcept(noexcept(_Sentinel<_Const, false>{_Last._Unwrapped()}))
requires _Wrapped && _Unwrappable_sentinel_for<sentinel_t<_Base_t>, const iterator_t<_Base_t>&> {
// clang-format on
return _Sentinel<_Const, false>{_Get_unwrapped(_Last)};
return _Sentinel<_Const, false>{_Last._Unwrapped()};
}
// clang-format off
_NODISCARD constexpr auto _Unwrapped() &&
noexcept(noexcept(_Sentinel<_Const, false>{_Get_unwrapped(_STD move(_Last))}))
requires _Wrapped && _Unwrappable_v<iterator_t<_Base_t>> {
noexcept(noexcept(_Sentinel<_Const, false>{_STD move(_Last)._Unwrapped()}))
requires _Wrapped && _Unwrappable_sentinel_for<sentinel_t<_Base_t>, iterator_t<_Base_t>> {
// clang-format on
return _Sentinel<_Const, false>{_Get_unwrapped(_STD move(_Last))};
return _Sentinel<_Const, false>{_STD move(_Last)._Unwrapped()};
}

static constexpr bool _Unwrap_when_unverified = _Do_unwrap_when_unverified_v<iterator_t<_Base_t>>;
Expand Down Expand Up @@ -2762,17 +2762,17 @@ namespace ranges {

// clang-format off
_NODISCARD constexpr auto _Unwrapped() const&
noexcept(noexcept(_Sentinel<_Const, false>{_Get_unwrapped(_Last), _Pred}))
requires _Wrapped && _Unwrappable_v<const iterator_t<_Base_t>&> {
noexcept(noexcept(_Sentinel<_Const, false>{_Last._Unwrapped(), _Pred}))
requires _Wrapped && _Unwrappable_sentinel_for<sentinel_t<_Base_t>, const iterator_t<_Base_t>&> {
// clang-format on
return _Sentinel<_Const, false>{_Get_unwrapped(_Last), _Pred};
return _Sentinel<_Const, false>{_Last._Unwrapped(), _Pred};
}
// clang-format off
_NODISCARD constexpr auto _Unwrapped() &&
noexcept(noexcept(_Sentinel<_Const, false>{_Get_unwrapped(_STD move(_Last)), _Pred}))
requires _Wrapped && _Unwrappable_v<iterator_t<_Base_t>> {
noexcept(noexcept(_Sentinel<_Const, false>{_STD move(_Last)._Unwrapped(), _Pred}))
requires _Wrapped && _Unwrappable_sentinel_for<sentinel_t<_Base_t>, iterator_t<_Base_t>> {
// clang-format on
return _Sentinel<_Const, false>{_Get_unwrapped(_STD move(_Last)), _Pred};
return _Sentinel<_Const, false>{_STD move(_Last)._Unwrapped(), _Pred};
}

static constexpr bool _Unwrap_when_unverified = _Do_unwrap_when_unverified_v<iterator_t<_Base_t>>;
Expand Down
17 changes: 12 additions & 5 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -1537,13 +1537,13 @@ namespace ranges {
if constexpr (is_pointer_v<_InIt>) {
_IFirst = reinterpret_cast<_InIt>(_IFirst_ch + _Count_bytes);
} else {
_IFirst += _Count;
_IFirst += static_cast<iter_difference_t<_InIt>>(_Count);
}

if constexpr (is_pointer_v<_OutIt>) {
_OFirst = reinterpret_cast<_OutIt>(_OFirst_ch + _Count_bytes);
} else {
_OFirst += _Count;
_OFirst += static_cast<iter_difference_t<_OutIt>>(_Count);
}
return {_STD move(_IFirst), _STD move(_OFirst)};
}
Expand Down Expand Up @@ -1592,13 +1592,13 @@ namespace ranges {
if constexpr (is_pointer_v<_InIt>) {
_IFirst = reinterpret_cast<_InIt>(_IFirst_ch + _Count_bytes);
} else {
_IFirst += _Count_bytes / sizeof(iter_value_t<_InIt>);
_IFirst += static_cast<iter_difference_t<_InIt>>(_Count_bytes / sizeof(iter_value_t<_InIt>));
}

if constexpr (is_pointer_v<_OutIt>) {
_OFirst = reinterpret_cast<_OutIt>(_OFirst_ch + _Count_bytes);
} else {
_OFirst += _Count_bytes / sizeof(iter_value_t<_OutIt>);
_OFirst += static_cast<iter_difference_t<_OutIt>>(_Count_bytes / sizeof(iter_value_t<_OutIt>));
}
return {_STD move(_IFirst), _STD move(_OFirst)};
}
Expand Down Expand Up @@ -1681,8 +1681,15 @@ _CONSTEXPR20 _Alloc_ptr_t<_Alloc> _Uninitialized_copy(
// note: only called internally from elsewhere in the STL
using _Ptrval = typename _Alloc::value_type*;

// In pre-concepts world, _Uninitialized_copy should only ever be called with an iterator
// and sentinel of the same type, so `_Get_unwrapped` is fine to call.
#ifdef __cpp_lib_concepts
auto _UFirst = _RANGES _Unwrap_iter<_Se>(_STD move(_First));
auto _ULast = _RANGES _Unwrap_sent<_InIt>(_STD move(_Last));
#else // ^^^ __cpp_lib_concepts / !__cpp_lib_concepts vvv
auto _UFirst = _Get_unwrapped(_STD move(_First));
strega-nil-ms marked this conversation as resolved.
Show resolved Hide resolved
auto _ULast = _Get_unwrapped(_STD move(_Last));
auto _ULast = _Get_unwrapped(_STD move(_Last));
#endif
strega-nil-ms marked this conversation as resolved.
Show resolved Hide resolved
strega-nil-ms marked this conversation as resolved.
Show resolved Hide resolved

constexpr bool _Can_memmove = _Sent_copy_cat<decltype(_UFirst), decltype(_ULast), _Ptrval>::_Bitcopy_constructible
&& _Uses_default_construct<_Alloc, _Ptrval, decltype(*_UFirst)>::value;
Expand Down
Loading