Skip to content

Commit

Permalink
C++20 move_iterator changes and move_sentinel (#787)
Browse files Browse the repository at this point in the history
* C++20 move_iterator changes and move_sentinel

Changes primarily come from P0896R4 "<ranges>", but the `operator<=>` from P1614R2 "Adding Spaceship <=> To The Library" is here as well.

I've also speculatively implemented the proposed resolutions of LWG-3293, LWG-3391, and LWG-3435.

I had to [patch a pair of libc++ tests](https://reviews.llvm.org/D79343) that fail with these changes; the LLVM reference is updated here to pull in those tests.

Drive-by:
* s/explicit constexpr/constexpr explicit/g (I somehow managed to sneak two occurrences into `subrange`)

* Skip flaky libc++ test (detached threads)
  • Loading branch information
CaseyCarter authored May 7, 2020
1 parent 88f8f44 commit 07627b6
Show file tree
Hide file tree
Showing 7 changed files with 572 additions and 138 deletions.
2 changes: 1 addition & 1 deletion llvm-project
Submodule llvm-project updated 1343 files
38 changes: 38 additions & 0 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,44 @@ _NODISCARD insert_iterator<_Container> inserter(_Container& _Cont, typename _Con
return insert_iterator<_Container>(_Cont, _Where);
}

#ifdef __cpp_lib_concepts
// CLASS TEMPLATE move_sentinel
template <semiregular _Se>
class move_sentinel {
public:
constexpr move_sentinel() = default;

constexpr explicit move_sentinel(_Se _Val) noexcept(is_nothrow_move_constructible_v<_Se>) // strengthened
: _Last{_STD move(_Val)} {}

// clang-format off
template <class _Se2>
requires convertible_to<const _Se2&, _Se>
constexpr move_sentinel(const move_sentinel<_Se2>& _Val)
noexcept(is_nothrow_constructible_v<_Se, const _Se2&>) // strengthened
: _Last{_Val._Get_last()} {}

template <class _Se2>
requires assignable_from<_Se&, const _Se2&>
constexpr move_sentinel& operator=(const move_sentinel<_Se2>& _Val)
noexcept(is_nothrow_assignable_v<_Se&, const _Se2&>) /* strengthened */ {
_Last = _Val._Get_last();
return *this;
}
// clang-format on

_NODISCARD constexpr _Se base() const noexcept(is_nothrow_copy_constructible_v<_Se>) /* strengthened */ {
return _Last;
}

_NODISCARD constexpr const _Se& _Get_last() const noexcept {
return _Last;
}

private:
_Se _Last{};
};
#endif // __cpp_lib_concepts

// CLASS TEMPLATE istream_iterator
template <class _Ty, class _Elem = char, class _Traits = char_traits<_Elem>, class _Diff = ptrdiff_t>
Expand Down
Loading

0 comments on commit 07627b6

Please sign in to comment.