libstdc++: Implement ranges::safe_range for C++20 (P1870R1)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 9 Dec 2019 17:35:24 +0000 (17:35 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 9 Dec 2019 17:35:24 +0000 (17:35 +0000)
commitb5b2e3879db9a251a2e7ff2553e188682d202c7e
tree50bc117800c5e6bc739168e9953df1fcb21505db
parent43c2de7a5720e0d6fbc5df8fc6fb03f2dbf164ff
libstdc++: Implement ranges::safe_range for C++20 (P1870R1)

This change replaces the __forwarding_range implementation detail with
the ranges::safe_range concept and adds the ranges::enable_safe_range
variable template for opt-in in to the concept.

It also adjusts the begin/end/rbegin/rend customization point objects to
match the new rules for accessing rvalue ranges only when safe to do so.

* include/bits/range_access.h (ranges::enable_safe_range): Define.
(ranges::begin, ranges::end, ranges::rbegin, ranges::rend): Constrain
to only accept types satisfying safe_range and treat argument as an
lvalue when calling a member of performing ADL.
(ranges::__detail::__range_impl, ranges::__detail::__forwarding_range):
Remove.
(ranges::range): Adjust definition.
(ranges::safe_range): Define.
(ranges::iterator_t, ranges::range_difference_t): Reorder definitions
to match the synopsis in the working draft.
(ranges::disable_sized_range): Remove duplicate definition.
* include/experimental/string_view (ranges::enable_safe_range): Add
partial specialization for std::experimental::basic_string_view.
* include/std/ranges (ranges::viewable_range, ranges::subrange)
(ranges::empty_view, ranges::iota_view): Use safe_range. Specialize
enable_safe_range.
(ranges::safe_iterator_t, ranges::safe_subrange_t): Define.
* include/std/span (ranges::enable_safe_range): Add partial
specialization for std::span.
* include/std/string_view (ranges::enable_safe_range): Likewise for
std::basic_string_view.
* testsuite/std/ranges/access/begin.cc: Adjust expected results.
* testsuite/std/ranges/access/cbegin.cc: Likewise.
* testsuite/std/ranges/access/cdata.cc: Likewise.
* testsuite/std/ranges/access/cend.cc: Likewise.
* testsuite/std/ranges/access/crbegin.cc: Likewise.
* testsuite/std/ranges/access/crend.cc: Likewise.
* testsuite/std/ranges/access/data.cc: Likewise.
* testsuite/std/ranges/access/end.cc: Likewise.
* testsuite/std/ranges/access/rbegin.cc: Likewise.
* testsuite/std/ranges/access/rend.cc: Likewise.
* testsuite/std/ranges/empty_view.cc: Test ranges::begin and
ranges::end instead of unqualified calls to begin and end.
* testsuite/std/ranges/safe_range.cc: New test.
* testsuite/std/ranges/safe_range_types.cc: New test.
* testsuite/util/testsuite_iterators.h: Add comment about safe_range.

From-SVN: r279135
20 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/range_access.h
libstdc++-v3/include/experimental/string_view
libstdc++-v3/include/std/ranges
libstdc++-v3/include/std/span
libstdc++-v3/include/std/string_view
libstdc++-v3/testsuite/std/ranges/access/begin.cc
libstdc++-v3/testsuite/std/ranges/access/cbegin.cc
libstdc++-v3/testsuite/std/ranges/access/cdata.cc
libstdc++-v3/testsuite/std/ranges/access/cend.cc
libstdc++-v3/testsuite/std/ranges/access/crbegin.cc
libstdc++-v3/testsuite/std/ranges/access/crend.cc
libstdc++-v3/testsuite/std/ranges/access/data.cc
libstdc++-v3/testsuite/std/ranges/access/end.cc
libstdc++-v3/testsuite/std/ranges/access/rbegin.cc
libstdc++-v3/testsuite/std/ranges/access/rend.cc
libstdc++-v3/testsuite/std/ranges/empty_view.cc
libstdc++-v3/testsuite/std/ranges/safe_range.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/ranges/safe_range_types.cc [new file with mode: 0644]
libstdc++-v3/testsuite/util/testsuite_iterators.h