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 4 commits
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
19 changes: 17 additions & 2 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -3211,8 +3211,23 @@ public:
using pointer = _Iter;

#ifdef __cpp_lib_concepts
using iterator_concept = input_iterator_tag;
using reference = iter_rvalue_reference_t<_Iter>;
private:
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{};
}
}

public:
using iterator_concept = decltype(_Get_iter_concept());

using reference = iter_rvalue_reference_t<_Iter>;
#else // ^^^ __cpp_lib_concepts / !__cpp_lib_concepts vvv
using reference =
conditional_t<is_reference_v<_Iter_ref_t<_Iter>>, remove_reference_t<_Iter_ref_t<_Iter>>&&, _Iter_ref_t<_Iter>>;
Expand Down
2 changes: 2 additions & 0 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
// P2415R2 What Is A view?
// P2418R2 Add Support For std::generator-like Types To std::format
// P2432R1 Fix istream_view
// P2520R0 move_iterator<T*> Should Be A Random-Access Iterator

// _HAS_CXX20 indirectly controls:
// P0619R4 Removing C++17-Deprecated Features
Expand Down Expand Up @@ -1409,6 +1410,7 @@
#define __cpp_lib_latch 201907L
#define __cpp_lib_list_remove_return_type 201806L
#define __cpp_lib_math_constants 201907L
#define __cpp_lib_move_iterator_concept 202207L
strega-nil-ms marked this conversation as resolved.
Show resolved Hide resolved
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
#define __cpp_lib_polymorphic_allocator 201902L

#if defined(__cpp_lib_concepts) // TRANSITION, GH-395
Expand Down
3 changes: 3 additions & 0 deletions tests/libcxx/skipped_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ utilities\format\format.functions\vformat.pass.cpp
# libc++ doesn't implement P2321R2's changes to vector<bool>::reference
containers\sequences\vector.bool\iterator_concept_conformance.compile.pass.cpp

# libc++ hasn't updated move_iterator for P2520R0
std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
strega-nil-ms marked this conversation as resolved.
Show resolved Hide resolved


# *** INTERACTIONS WITH CONTEST / C1XX THAT UPSTREAM LIKELY WON'T FIX ***
# Tracked by VSO-593630 "<filesystem> Enable libcxx filesystem tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ static_assert(contiguous_iterator<int Test::*volatile*>);
static_assert(contiguous_iterator<int Test::*const volatile*>);

// Tests for move_iterator specializations
static_assert(input_iterator<move_iterator<volatile int*>>);
static_assert(input_iterator<move_iterator<const volatile int*>>);
static_assert(input_iterator<move_iterator<volatile double*>>);
static_assert(input_iterator<move_iterator<const volatile double*>>);
static_assert(input_iterator<move_iterator<volatile nullptr_t*>>);
static_assert(input_iterator<move_iterator<const volatile nullptr_t*>>);
static_assert(input_iterator<move_iterator<volatile Unscoped*>>);
static_assert(input_iterator<move_iterator<const volatile Unscoped*>>);
static_assert(input_iterator<move_iterator<volatile Scoped*>>);
static_assert(input_iterator<move_iterator<const volatile Scoped*>>);
static_assert(input_iterator<move_iterator<Test* volatile*>>);
static_assert(input_iterator<move_iterator<Test* const volatile*>>);
static_assert(input_iterator<move_iterator<int Test::*volatile*>>);
static_assert(input_iterator<move_iterator<int Test::*const volatile*>>);
static_assert(random_access_iterator<move_iterator<volatile int*>>);
static_assert(random_access_iterator<move_iterator<const volatile int*>>);
static_assert(random_access_iterator<move_iterator<volatile double*>>);
static_assert(random_access_iterator<move_iterator<const volatile double*>>);
static_assert(random_access_iterator<move_iterator<volatile nullptr_t*>>);
static_assert(random_access_iterator<move_iterator<const volatile nullptr_t*>>);
static_assert(random_access_iterator<move_iterator<volatile Unscoped*>>);
static_assert(random_access_iterator<move_iterator<const volatile Unscoped*>>);
static_assert(random_access_iterator<move_iterator<volatile Scoped*>>);
static_assert(random_access_iterator<move_iterator<const volatile Scoped*>>);
static_assert(random_access_iterator<move_iterator<Test* volatile*>>);
static_assert(random_access_iterator<move_iterator<Test* const volatile*>>);
static_assert(random_access_iterator<move_iterator<int Test::*volatile*>>);
static_assert(random_access_iterator<move_iterator<int Test::*const volatile*>>);

int main() {} // COMPILE-ONLY
10 changes: 6 additions & 4 deletions tests/std/tests/P0896R4_ranges_iterator_machinery/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3271,17 +3271,19 @@ struct std::common_type<move_iterator_test::input_iter<true>::rvalue_reference,

namespace move_iterator_test {
// Validate the iterator_concept/iterator_category metaprogramming
STATIC_ASSERT(same_as<move_iterator<simple_contiguous_iter<>>::iterator_concept, input_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_contiguous_iter<>>::iterator_concept, random_access_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_contiguous_iter<>>::iterator_category, random_access_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_random_iter<>>::iterator_concept, input_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_random_iter<>>::iterator_concept, random_access_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_random_iter<>>::iterator_category, random_access_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_bidi_iter<>>::iterator_concept, input_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_bidi_iter<>>::iterator_concept, bidirectional_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_bidi_iter<>>::iterator_category, bidirectional_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_forward_iter<>>::iterator_concept, input_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_forward_iter<>>::iterator_concept, forward_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_forward_iter<>>::iterator_category, forward_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_input_iter>::iterator_concept, input_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<simple_input_iter>::iterator_category, input_iterator_tag>);
STATIC_ASSERT(same_as<move_iterator<input_iter<true>>::iterator_concept, input_iterator_tag>);
STATIC_ASSERT(!has_member_iter_category<move_iterator<input_iter<true>>>);
STATIC_ASSERT(same_as<move_iterator<input_iter<true>>::iterator_concept, input_iterator_tag>);
STATIC_ASSERT(!has_member_iter_category<move_iterator<input_iter<false>>>);
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

// Validate that move_iterator<some_proxy_iterator>::reference is iter_rvalue_reference_t<some_proxy_iterator>
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