[PATCH] [RFC] span-v2: using concepts, constraints and ranges:: instead of enable_if

Jonathan Wakely jwakely@redhat.com
Thu Dec 5 13:50:00 GMT 2019


On 21/11/19 19:56 -0500, JeanHeyd Meneide wrote:
>Thank you for the review!
>
>- I moved the concepts back into the class and changed them to
>template aliases because class local concepts aren't a thing that
>works.
>     + They are not inline constexpr bools because that ICE's GCC
>pretty hard, as you explained to me earlier, so we use ::value in some
>places rather than _v
>- I named the alias __is_array_convertible, to match what the intent
>is, and named the template parameters very explicitly.
>     + I moved it into type_traits, but I didn't change
>bits/unique_ptr.h or shared_ptr yet because I'm not confident I can do
>that quickly in one go.
>     + (And it should probably be a different patch anyways, but it
>should be in the right place when we introduce it here.)



>+      template<typename _Iter>
>+	using __is_compatible_iterator = __and_<
>+	  bool_constant<contiguous_iterator<_Iter>>,
>+	  is_lvalue_reference<iter_reference_t<_Iter>>,
>+	  is_same<iter_value_t<_Iter>, remove_cvref_t<iter_reference_t<_Iter>>>,
>+	  __is_array_convertible<_Type, remove_reference_t<iter_reference_t<_Iter>>>>;

This line is too long, we stick to < 80 columns. I'm changing it to:

      template<typename _Iter, typename _Ref = iter_reference_t<_Iter>>
	using __is_compatible_iterator = __and_<
	  bool_constant<contiguous_iterator<_Iter>>,
	  is_lvalue_reference<iter_reference_t<_Iter>>,
	  is_same<iter_value_t<_Iter>, remove_cvref_t<_Ref>>,
	  __is_array_convertible<_Type, remove_reference_t<_Ref>>>;

>     public:
>       // member types
>       using value_type             = remove_cv_t<_Type>;
>       using element_type           = _Type;
>-      using index_type             = size_t;
>+      using size_type              = size_t;

The comment about size_type was still there, so I'm removing that:

-      // Official wording has no size_type -- why??
-      // using size_type = size_t;


>@@ -505,27 +426,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>     span(const array<_Type, _ArrayExtent>&)
>       -> span<const _Type, _ArrayExtent>;
>
>-#ifdef _GLIBCXX_P1394
>-
>-  template<typename _ContiguousIterator, typename _Sentinel>
>+  template<contiguous_iterator _ContiguousIterator, typename _Sentinel>
>     span(_ContiguousIterator, _Sentinel)
>-      -> span<remove_reference_t<
>-	typename iterator_traits<_ContiguousIterator>::reference>>;
>+      -> span<remove_reference_t<ranges::range_reference_t<_ContiguousIterator>>>;

This line's too long, so I'm renaming _ContiguousIterator to _Iter.
When it's a constrained parameter I think we can use less verbose
names. There's no need to use the template parameter's name to express
the (implied, unchecked) requirements on it when we constrain it with
a concept.

Since <span> is now using concepts throughout, I'm adding this around
the whole thing:

#if __cpp_lib_concepts

This also causes two new FAILs in 23_containers/span/lwg3255.cc but
that turns out to be a bug in the test, which fails now t hat you've
fixed a bug in span. I'll fix that as well.

With those changes I'm committing it to trunk, thanks!

Tested powerpc64le-linux, committed to trunk as attached.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 20945 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20191205/d495625c/attachment.bin>


More information about the Libstdc++ mailing list