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

Implement P2520R0: move_iterator<T*> should be a random access iterator #2958

Merged
merged 6 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
30 changes: 14 additions & 16 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -3186,26 +3186,11 @@ class move_sentinel;

template <class>
struct _Move_iterator_category {};
template <class _Iter>
struct _Move_iterator_concept {
constexpr static auto _Get_concept() {
if constexpr (random_access_iterator<_Iter>) {
return random_access_iterator_tag{};
} else if constexpr (bidirectional_iterator<_Iter>) {
return bidirectional_iterator_tag{};
} else if constexpr (forward_iterator<_Iter>) {
return forward_iterator_tag{};
} else {
return input_iterator_tag{};
}
}
using iterator_concept = decltype(_Get_concept());
};

// clang-format off
template <class _Iter>
requires requires { typename _Iter_cat_t<_Iter>; }
struct _Move_iterator_category<_Iter> : _Move_iterator_concept<_Iter> {
struct _Move_iterator_category<_Iter> {
using iterator_category = conditional_t<derived_from<_Iter_cat_t<_Iter>, random_access_iterator_tag>,
random_access_iterator_tag, _Iter_cat_t<_Iter>>;
};
Expand All @@ -3226,6 +3211,19 @@ public:
using pointer = _Iter;

#ifdef __cpp_lib_concepts
constexpr static auto _Get_iter_concept() {
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
if constexpr (random_access_iterator<_Iter>) {
return random_access_iterator_tag{};
} else if constexpr (bidirectional_iterator<_Iter>) {
return bidirectional_iterator_tag{};
} else if constexpr (forward_iterator<_Iter>) {
return forward_iterator_tag{};
} else {
return input_iterator_tag{};
}
}
using iterator_concept = decltype(_Get_iter_concept());

using reference = iter_rvalue_reference_t<_Iter>;
#else // ^^^ __cpp_lib_concepts / !__cpp_lib_concepts vvv
using reference =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,20 @@ STATIC_ASSERT(__cpp_lib_memory_resource == 201603L);
#endif
#endif

#if _HAS_CXX20
#ifndef __cpp_lib_move_iterator_concept
#error __cpp_lib_move_iterator_concept is not defined
#elif __cpp_lib_move_iterator_concept != 202207L
#error __cpp_lib_move_iterator_concept is not 202207L
#else
STATIC_ASSERT(__cpp_lib_move_iterator_concept == 202207L);
#endif
#else
#ifdef __cpp_lib_move_iterator_concept
#error __cpp_lib_move_iterator_concept is defined
#endif
#endif

#if _HAS_CXX23
#ifndef __cpp_lib_move_only_function
#error __cpp_lib_move_only_function is not defined
Expand Down