-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc++] Move _ITER_TRAITS and _ITER_CONCEPT into <__iterator/concepts.h> #140528
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
Merged
+80
−96
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5e496e9
to
a6c12b9
Compare
0d98d10
to
a5fb1bc
Compare
a5fb1bc
to
ebe6812
Compare
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) Changes
Full diff: https://github.com/llvm/llvm-project/pull/140528.diff 4 Files Affected:
diff --git a/libcxx/include/__iterator/concepts.h b/libcxx/include/__iterator/concepts.h
index ddfc84ed710cb..20a1ab4691100 100644
--- a/libcxx/include/__iterator/concepts.h
+++ b/libcxx/include/__iterator/concepts.h
@@ -29,16 +29,19 @@
#include <__iterator/incrementable_traits.h>
#include <__iterator/iter_move.h>
#include <__iterator/iterator_traits.h>
-#include <__iterator/readable_traits.h>
#include <__memory/pointer_traits.h>
#include <__type_traits/add_pointer.h>
#include <__type_traits/common_reference.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/disjunction.h>
+#include <__type_traits/enable_if.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/invoke.h>
#include <__type_traits/is_pointer.h>
#include <__type_traits/is_primary_template.h>
#include <__type_traits/is_reference.h>
#include <__type_traits/is_referenceable.h>
+#include <__type_traits/is_valid_expansion.h>
#include <__type_traits/remove_cv.h>
#include <__type_traits/remove_cvref.h>
#include <__utility/forward.h>
@@ -151,6 +154,42 @@ concept sized_sentinel_for =
{ __i - __s } -> same_as<iter_difference_t<_Ip>>;
};
+template <class _Iter>
+struct __iter_traits_cache {
+ using type _LIBCPP_NODEBUG =
+ _If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
+};
+template <class _Iter>
+using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
+
+struct __iter_concept_concept_test {
+ template <class _Iter>
+ using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
+};
+struct __iter_concept_category_test {
+ template <class _Iter>
+ using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
+};
+struct __iter_concept_random_fallback {
+ template <class _Iter>
+ using _Apply _LIBCPP_NODEBUG =
+ __enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
+};
+
+template <class _Iter, class _Tester>
+struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {};
+
+template <class _Iter>
+struct __iter_concept_cache {
+ using type _LIBCPP_NODEBUG =
+ _Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
+ __test_iter_concept<_Iter, __iter_concept_category_test>,
+ __test_iter_concept<_Iter, __iter_concept_random_fallback> >;
+};
+
+template <class _Iter>
+using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
+
// [iterator.concept.input]
template <class _Ip>
concept input_iterator = input_or_output_iterator<_Ip> && indirectly_readable<_Ip> && requires {
diff --git a/libcxx/include/__iterator/iterator_traits.h b/libcxx/include/__iterator/iterator_traits.h
index 8256580acb291..221d36614db08 100644
--- a/libcxx/include/__iterator/iterator_traits.h
+++ b/libcxx/include/__iterator/iterator_traits.h
@@ -27,14 +27,12 @@
#include <__type_traits/conditional.h>
#include <__type_traits/detected_or.h>
#include <__type_traits/disjunction.h>
-#include <__type_traits/enable_if.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/is_convertible.h>
#include <__type_traits/is_object.h>
#include <__type_traits/is_primary_template.h>
#include <__type_traits/is_reference.h>
#include <__type_traits/is_referenceable.h>
-#include <__type_traits/is_valid_expansion.h>
#include <__type_traits/nat.h>
#include <__type_traits/remove_const.h>
#include <__type_traits/remove_cv.h>
@@ -73,42 +71,6 @@ struct random_access_iterator_tag : public bidirectional_iterator_tag {};
struct contiguous_iterator_tag : public random_access_iterator_tag {};
#endif
-template <class _Iter>
-struct __iter_traits_cache {
- using type _LIBCPP_NODEBUG =
- _If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
-};
-template <class _Iter>
-using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
-
-struct __iter_concept_concept_test {
- template <class _Iter>
- using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
-};
-struct __iter_concept_category_test {
- template <class _Iter>
- using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
-};
-struct __iter_concept_random_fallback {
- template <class _Iter>
- using _Apply _LIBCPP_NODEBUG =
- __enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
-};
-
-template <class _Iter, class _Tester>
-struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {};
-
-template <class _Iter>
-struct __iter_concept_cache {
- using type _LIBCPP_NODEBUG =
- _Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
- __test_iter_concept<_Iter, __iter_concept_category_test>,
- __test_iter_concept<_Iter, __iter_concept_random_fallback> >;
-};
-
-template <class _Iter>
-using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
-
template <class _Tp>
struct __has_iterator_typedefs {
private:
@@ -195,16 +157,6 @@ concept __specifies_members = requires {
requires __has_member_iterator_category<_Ip>;
};
-template <class>
-struct __iterator_traits_member_pointer_or_void {
- using type _LIBCPP_NODEBUG = void;
-};
-
-template <__has_member_pointer _Tp>
-struct __iterator_traits_member_pointer_or_void<_Tp> {
- using type _LIBCPP_NODEBUG = typename _Tp::pointer;
-};
-
template <class _Tp>
concept __cpp17_iterator_missing_members = !__specifies_members<_Tp> && __iterator_traits_detail::__cpp17_iterator<_Tp>;
@@ -304,6 +256,9 @@ struct __iterator_traits_difference_type<_Ip> {
template <class>
struct __iterator_traits {};
+template <class _Tp>
+using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer;
+
// [iterator.traits]/3.1
// If `I` has valid ([temp.deduct]) member types `difference-type`, `value-type`, `reference`, and
// `iterator-category`, then `iterator-traits<I>` has the following publicly accessible members:
@@ -312,7 +267,7 @@ struct __iterator_traits<_Ip> {
using iterator_category = typename _Ip::iterator_category;
using value_type = typename _Ip::value_type;
using difference_type = typename _Ip::difference_type;
- using pointer = typename __iterator_traits_member_pointer_or_void<_Ip>::type;
+ using pointer = __detected_or_t<void, __pointer_member, _Ip>;
using reference = typename _Ip::reference;
};
diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_concepts.pass.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_concepts.compile.pass.cpp
similarity index 52%
rename from libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_concepts.pass.cpp
rename to libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_concepts.compile.pass.cpp
index d551a551795ff..ffe473c97fedc 100644
--- a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_concepts.pass.cpp
+++ b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_concepts.compile.pass.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03
+// REQUIRES: std-at-least-c++20
// ITER_TRAITS(I)
@@ -19,6 +19,7 @@
// random_access_iterator_tag.
// (1.4) -- Otherwise, ITER_CONCEPT(I) does not denote a type.
+#include <__iterator/concepts.h>
#include <__type_traits/is_valid_expansion.h>
#include <cstddef>
#include <iterator>
@@ -30,19 +31,19 @@ struct OtherTagTwo : std::output_iterator_tag {};
struct MyIter {
using iterator_category = std::random_access_iterator_tag;
- using iterator_concept = int;
- using value_type = char;
- using difference_type = std::ptrdiff_t;
- using pointer = char*;
- using reference = char&;
+ using iterator_concept = int;
+ using value_type = char;
+ using difference_type = std::ptrdiff_t;
+ using pointer = char*;
+ using reference = char&;
};
struct MyIter2 {
using iterator_category = OtherTag;
- using value_type = char;
- using difference_type = std::ptrdiff_t;
- using pointer = char*;
- using reference = char&;
+ using value_type = char;
+ using difference_type = std::ptrdiff_t;
+ using pointer = char*;
+ using reference = char&;
};
struct MyIter3 {};
@@ -52,10 +53,10 @@ struct EmptyWithSpecial {};
template <>
struct std::iterator_traits<MyIter3> {
using iterator_category = OtherTagTwo;
- using value_type = char;
- using difference_type = std::ptrdiff_t;
- using pointer = char*;
- using reference = char&;
+ using value_type = char;
+ using difference_type = std::ptrdiff_t;
+ using pointer = char*;
+ using reference = char&;
};
template <>
@@ -63,29 +64,18 @@ struct std::iterator_traits<EmptyWithSpecial> {
// empty non-default.
};
-int main(int, char**) {
- // If the qualified-id ITER_TRAITS(I)::iterator_concept is valid and names a type,
- // then ITER_CONCEPT(I) denotes that type.
- {
-#if TEST_STD_VER > 17
- ASSERT_SAME_TYPE(std::_ITER_CONCEPT<char*>, std::contiguous_iterator_tag);
-#endif
- ASSERT_SAME_TYPE(std::_ITER_CONCEPT<MyIter>, int);
- }
- // Otherwise, if the qualified-id ITER_TRAITS(I)::iterator_category is valid
- // and names a type, then ITER_CONCEPT(I) denotes that type.
- {
- ASSERT_SAME_TYPE(std::_ITER_CONCEPT<MyIter2>, OtherTag);
- ASSERT_SAME_TYPE(std::_ITER_CONCEPT<MyIter3>, OtherTagTwo);
- }
- // FIXME - This requirement makes no sense to me. Why does an empty type with
- // an empty default iterator_traits get a category of random?
- {
- ASSERT_SAME_TYPE(std::_ITER_CONCEPT<Empty>, std::random_access_iterator_tag);
- }
- {
- static_assert(!std::_IsValidExpansion<std::_ITER_CONCEPT, EmptyWithSpecial>::value, "");
- }
+// If the qualified-id ITER_TRAITS(I)::iterator_concept is valid and names a type,
+// then ITER_CONCEPT(I) denotes that type.
+ASSERT_SAME_TYPE(std::_ITER_CONCEPT<char*>, std::contiguous_iterator_tag);
+ASSERT_SAME_TYPE(std::_ITER_CONCEPT<MyIter>, int);
- return 0;
-}
+// Otherwise, if the qualified-id ITER_TRAITS(I)::iterator_category is valid
+// and names a type, then ITER_CONCEPT(I) denotes that type.
+ASSERT_SAME_TYPE(std::_ITER_CONCEPT<MyIter2>, OtherTag);
+ASSERT_SAME_TYPE(std::_ITER_CONCEPT<MyIter3>, OtherTagTwo);
+
+// FIXME - This requirement makes no sense to me. Why does an empty type with
+// an empty default iterator_traits get a category of random?
+ASSERT_SAME_TYPE(std::_ITER_CONCEPT<Empty>, std::random_access_iterator_tag);
+
+static_assert(!std::_IsValidExpansion<std::_ITER_CONCEPT, EmptyWithSpecial>::value);
diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_traits.compile.pass.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_traits.compile.pass.cpp
index 50047c1b90513..066587d68cd3b 100644
--- a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_traits.compile.pass.cpp
+++ b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/cpp20_iter_traits.compile.pass.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03
+// REQUIRES: std-at-least-c++20
// ITER_TRAITS(I)
@@ -14,7 +14,7 @@
// a specialization generated from the primary template. Otherwise,
// ITER_TRAITS(I) denotes iterator_traits<I>.
-#include <iterator>
+#include <__iterator/concepts.h>
#include <type_traits>
#include "test_iterators.h"
@@ -27,8 +27,8 @@ template<> struct std::iterator_traits<B> {};
template<> struct std::iterator_traits<C> : std::iterator_traits<A> {};
template<> struct std::iterator_traits<D> : std::iterator_traits<int*> {};
-static_assert(std::is_same<std::_ITER_TRAITS<int*>, std::iterator_traits<int*>>::value, "");
-static_assert(std::is_same<std::_ITER_TRAITS<A>, A>::value, "");
-static_assert(std::is_same<std::_ITER_TRAITS<B>, std::iterator_traits<B>>::value, "");
-static_assert(std::is_same<std::_ITER_TRAITS<C>, std::iterator_traits<C>>::value, "");
-static_assert(std::is_same<std::_ITER_TRAITS<D>, std::iterator_traits<D>>::value, "");
+static_assert(std::is_same<std::_ITER_TRAITS<int*>, std::iterator_traits<int*>>::value);
+static_assert(std::is_same<std::_ITER_TRAITS<A>, A>::value);
+static_assert(std::is_same<std::_ITER_TRAITS<B>, std::iterator_traits<B>>::value);
+static_assert(std::is_same<std::_ITER_TRAITS<C>, std::iterator_traits<C>>::value);
+static_assert(std::is_same<std::_ITER_TRAITS<D>, std::iterator_traits<D>>::value);
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
_ITER_TRAITS
and_ITER_CONCEPT
are really implenentation details of<__iterator/concetps.h>
, so it makes more sense to put them there than into<__iterator/iterator_traits.h>
.