[libcxx-commits] [PATCH] D108855: [libcxx] contiguous iterator concept: don't require pointer or complete element types

Joe Loser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 27 20:36:45 PDT 2021


jloser created this revision.
jloser requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

`contiguous_iterator` requires the iterator type passed is either a
pointer type or that the element type of the iterator is a complete
object type. These constraints are not part of the current wording in
defining the `contiguous_iterator` concept - adjust the concept to
reflect this.

Remove two tests checking that the types model `contiguous_iterator`.
With the new definition, the current types would hard error in checking
the constraint when evaluating `std::to_address`.

Inspired from discussion at https://reviews.llvm.org/D108645.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108855

Files:
  libcxx/include/__iterator/concepts.h
  libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp


Index: libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp
===================================================================
--- libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp
+++ libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp
@@ -130,7 +130,6 @@
 };
 
 static_assert(std::random_access_iterator<wrong_iter_reference_t>);
-static_assert(!std::contiguous_iterator<wrong_iter_reference_t>);
 
 struct no_element_type {
     typedef std::contiguous_iterator_tag    iterator_category;
@@ -164,7 +163,6 @@
 };
 
 static_assert(std::random_access_iterator<no_element_type>);
-static_assert(!std::contiguous_iterator<no_element_type>);
 
 struct to_address_wrong_return_type {
     typedef std::contiguous_iterator_tag    iterator_category;
Index: libcxx/include/__iterator/concepts.h
===================================================================
--- libcxx/include/__iterator/concepts.h
+++ libcxx/include/__iterator/concepts.h
@@ -174,7 +174,6 @@
   derived_from<_ITER_CONCEPT<_Ip>, contiguous_iterator_tag> &&
   is_lvalue_reference_v<iter_reference_t<_Ip>> &&
   same_as<iter_value_t<_Ip>, remove_cvref_t<iter_reference_t<_Ip>>> &&
-  (is_pointer_v<_Ip> || requires { sizeof(__pointer_traits_element_type<_Ip>); }) &&
   requires(const _Ip& __i) {
     { _VSTD::to_address(__i) } -> same_as<add_pointer_t<iter_reference_t<_Ip>>>;
   };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108855.369228.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210828/2e9198b5/attachment.bin>


More information about the libcxx-commits mailing list