]> git.ipfire.org Git - thirdparty/gcc.git/commit
Improve constraints for std::span constructors
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 9 Sep 2019 11:12:38 +0000 (11:12 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 9 Sep 2019 11:12:38 +0000 (11:12 +0000)
commita1823cbbcbd772b4f2bb758f9196a215a1d9abd0
treee3d6a047ad28871046ab9b7279b472cfedd58a7a
parent668cbe0a29e9a5831b14d6d745c55bd5eb2cb52d
Improve constraints for std::span constructors

This patch simplifies the constraints on the constructors from arrays by
removing the redundant checks that element_type and value_type are
convertible to element_type. The incorrect uses of __adl_data in those
constructors are removed as well (they should use std::data not
std::ranges::data, and the former doesn't use ADL).

The range/container constructors are now constrained to exclude all
specializations of std::span, not just the current instantiation. The
range constructor now also checks s subset of the contiguous_range
requirements.

All relevant constructor constraints now use the _Require helper in
order to short circuit and avoid unnecessary instantiations after the
first failed constraint.

A new constructor supports initialization from different specializations
of std::span<OtherType, OtherExtent>, as specified in the C++20 draft.

* include/bits/range_access.h (__adl_to_address): Remove.
* include/std/span (__is_base_derived_safe_convertible_v): Replace
with span::__is_compatible.
(__is_std_array_v): Replace with __is_std_array class template and
partial specializations.
(__is_std_array, __is_std_span): New class templates and partial
specializations.
(span::__is_compatible): New alias template for SFINAE constraints.
(span::span(element_type (&)[N])): Remove redundant constraints. Do
not use __adl_data to obtain a pointer.
(span::span(array<value_type, N>&)): Likewise.
(span::span(const array<value_type, N>&)): Likewise.
[_GLIBCXX_P1394] (span::iter_reference_t, span::iterator_t)
(span::iter_value_t, span::derived_from): New alias templates for
SFINAE constraints, until the equivalents are supported in <concepts>
and <iterator>.
[_GLIBCXX_P1394] (span::__is_compatible_iterator): New alias template
for SFINAE constraints.
[_GLIBCXX_P1394] (span::is_compatible_range): New class template for
SFINAE constraints.
[_GLIBCXX_P1394] (span::span(Range&&)): Improve constraints.
[_GLIBCXX_P1394] (span::span(ContiguousIterator, Sentinel)): Likewise.
Use std::to_address instead of __adl_to_address.
[_GLIBCXX_P1394] (span::span(ContiguousIterator, size_type)): Likewise.
[!_GLIBCXX_P1394] (span::__is_compatible_container): New alias
template for SFINAE constraints.
[!_GLIBCXX_P1394] (span::span(Container&))
(span::span(const Container&)): Improve constraints.
[!_GLIBCXX_P1394] (span::span(pointer, size_type))
(span::span(pointer, pointer)): Remove redundant cast of pointer.
(span(const span<OType, OExtent>&)): New constructor.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@275513 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/range_access.h
libstdc++-v3/include/std/span