From: Jonathan Wakely Date: Thu, 31 Oct 2019 21:42:18 +0000 (+0000) Subject: Partial implementation of C++20 of header X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=328b52d6751733f6e0f2d31feca44e1d8f2abfc6;p=gcc.git Partial implementation of C++20 of header * doc/doxygen/user.cfg.in: Add new header. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/precompiled/stdc++.h: Include new header. * include/std/ranges: New header. (ranges::sentinel_t, ranges::range_value_t, ranges::range_reference_t) (ranges::range_rvalue_reference_t, ranges::sized_range) (ranges::output_range, ranges::input_ranges, ranges::forward_range) (ranges::bidirectional_range, ranges::random_access_range) (ranges::contiguous_range, ranges::common::range): Define. * testsuite/24_iterators/headers/iterator/synopsis_c++20.cc: Check that disabled_sized_sentinel can be specialized. * testsuite/std/ranges/access/begin.cc: Include instead of . * 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/empty.cc: Likewise. * testsuite/std/ranges/access/end.cc: Likewise. * testsuite/std/ranges/access/end_neg.cc: Likewise. * testsuite/std/ranges/access/rbegin.cc: Likewise. * testsuite/std/ranges/access/rend.cc: Likewise. * testsuite/std/ranges/access/size.cc: Likewise. * testsuite/std/ranges/access/size_neg.cc: Likewise. * testsuite/std/ranges/headers/ranges/synopsis.cc: New test. * testsuite/std/ranges/range.cc: New test. * testsuite/std/ranges/refinements.cc: New test. * testsuite/std/ranges/sized.cc: New test. * testsuite/util/testsuite_iterators.h: Add aliases for range types. (output_iterator_wrapper::WritableObject::operator=): Add const qualifier so that output_iterator_wrapper satisfies writable. From-SVN: r277697 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2a472895117..1004d76a77d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,40 @@ 2019-10-31 Jonathan Wakely + * doc/doxygen/user.cfg.in: Add new header. + * include/Makefile.am: Add new header. + * include/Makefile.in: Regenerate. + * include/precompiled/stdc++.h: Include new header. + * include/std/ranges: New header. + (ranges::sentinel_t, ranges::range_value_t, ranges::range_reference_t) + (ranges::range_rvalue_reference_t, ranges::sized_range) + (ranges::output_range, ranges::input_ranges, ranges::forward_range) + (ranges::bidirectional_range, ranges::random_access_range) + (ranges::contiguous_range, ranges::common::range): Define. + * testsuite/24_iterators/headers/iterator/synopsis_c++20.cc: Check + that disabled_sized_sentinel can be specialized. + * testsuite/std/ranges/access/begin.cc: Include instead of + . + * 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/empty.cc: Likewise. + * testsuite/std/ranges/access/end.cc: Likewise. + * testsuite/std/ranges/access/end_neg.cc: Likewise. + * testsuite/std/ranges/access/rbegin.cc: Likewise. + * testsuite/std/ranges/access/rend.cc: Likewise. + * testsuite/std/ranges/access/size.cc: Likewise. + * testsuite/std/ranges/access/size_neg.cc: Likewise. + * testsuite/std/ranges/headers/ranges/synopsis.cc: New test. + * testsuite/std/ranges/range.cc: New test. + * testsuite/std/ranges/refinements.cc: New test. + * testsuite/std/ranges/sized.cc: New test. + * testsuite/util/testsuite_iterators.h: Add aliases for range types. + (output_iterator_wrapper::WritableObject::operator=): Add const + qualifier so that output_iterator_wrapper satisfies writable. + * testsuite/20_util/add_pointer/value.cc: Check void types. * include/bits/range_access.h (__sizable): Rename to __sentinel_size. diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in b/libstdc++-v3/doc/doxygen/user.cfg.in index 3c0295d99a5..42001016721 100644 --- a/libstdc++-v3/doc/doxygen/user.cfg.in +++ b/libstdc++-v3/doc/doxygen/user.cfg.in @@ -829,6 +829,7 @@ INPUT = @srcdir@/doc/doxygen/doxygroups.cc \ include/ostream \ include/queue \ include/random \ + include/ranges \ include/ratio \ include/regex \ include/scoped_allocator \ diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 401c87ad103..3e526dc14b7 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -64,6 +64,7 @@ std_headers = \ ${std_srcdir}/ostream \ ${std_srcdir}/queue \ ${std_srcdir}/random \ + ${std_srcdir}/ranges \ ${std_srcdir}/ratio \ ${std_srcdir}/regex \ ${std_srcdir}/scoped_allocator \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index e0a74963547..d9eb306a213 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -408,6 +408,7 @@ std_headers = \ ${std_srcdir}/ostream \ ${std_srcdir}/queue \ ${std_srcdir}/random \ + ${std_srcdir}/ranges \ ${std_srcdir}/ratio \ ${std_srcdir}/regex \ ${std_srcdir}/scoped_allocator \ diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h index fefd6e76845..57c3e2e32ee 100644 --- a/libstdc++-v3/include/precompiled/stdc++.h +++ b/libstdc++-v3/include/precompiled/stdc++.h @@ -138,7 +138,7 @@ // #include #include #include -// #include +#include #include // #include #include diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges new file mode 100644 index 00000000000..884fa1d1408 --- /dev/null +++ b/libstdc++-v3/include/std/ranges @@ -0,0 +1,112 @@ +// -*- C++ -*- + +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received __a copy of the GNU General Public License and +// __a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file include/ranges + * This is a Standard C++ Library header. + * @ingroup concepts + */ + +#ifndef _GLIBCXX_RANGES +#define _GLIBCXX_RANGES 1 + +#if __cplusplus > 201703L + +#pragma GCC system_header + +#include + +#if __cpp_lib_concepts + +#include + +/** + * @defgroup ranges Ranges + * + * Components for dealing with ranges of elements. + */ + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION +namespace ranges +{ + // [range.range] The range concept. + // Defined in + // template concept range; + + template + using sentinel_t = decltype(ranges::end(std::declval<_Range&>())); + + template + using range_value_t = iter_value_t>; + + template + using range_reference_t = iter_reference_t>; + + template + using range_rvalue_reference_t + = iter_rvalue_reference_t>; + + // [range.sized] The sized_range concept. + // Defined in + // template concept sized_range; + + // [range.refinements] + + template + concept output_range + = range<_Range> && output_iterator, _Tp>; + + template + concept input_range = range<_Tp> && input_iterator>; + + template + concept forward_range + = input_range<_Tp> && forward_iterator>; + + template + concept bidirectional_range + = forward_range<_Tp> && bidirectional_iterator>; + + template + concept random_access_range + = bidirectional_range<_Tp> && random_access_iterator>; + + template + concept contiguous_range + = random_access_range<_Tp> && contiguous_iterator> + && requires(_Tp& __t) + { + { ranges::data(__t) } -> same_as>>; + }; + + template + concept common_range + = range<_Tp> && same_as, sentinel_t<_Tp>>; +} // namespace ranges +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace +#endif // library concepts +#endif // C++2a +#endif /* _GLIBCXX_RANGES */ diff --git a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc index 2dbfb767fdb..824b0b4f38c 100644 --- a/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc +++ b/libstdc++-v3/testsuite/24_iterators/headers/iterator/synopsis_c++20.cc @@ -78,6 +78,9 @@ namespace std struct unreachable_sentinel_t; } +struct I { }; +template<> constexpr bool std::disable_sized_sentinel = true; + namespace __gnu_test { // customization points diff --git a/libstdc++-v3/testsuite/std/ranges/access/begin.cc b/libstdc++-v3/testsuite/std/ranges/access/begin.cc index 100dcf69c6e..e4c245a76bb 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/begin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/begin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc b/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc index 34dd7fec3c6..54db3658896 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/cbegin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include using std::same_as; diff --git a/libstdc++-v3/testsuite/std/ranges/access/cdata.cc b/libstdc++-v3/testsuite/std/ranges/access/cdata.cc index 9a1ab5b9607..b16c99607a5 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/cdata.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/cdata.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include void diff --git a/libstdc++-v3/testsuite/std/ranges/access/cend.cc b/libstdc++-v3/testsuite/std/ranges/access/cend.cc index 94349c35d51..3b57b3dbcaf 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/cend.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/cend.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include using std::same_as; diff --git a/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc b/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc index 24939ac658e..d9e5b0cbef7 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/crbegin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/crend.cc b/libstdc++-v3/testsuite/std/ranges/access/crend.cc index ef0fb0e6b09..e56491973b2 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/crend.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/crend.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/data.cc b/libstdc++-v3/testsuite/std/ranges/access/data.cc index d9129d055fc..49321640182 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/data.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/data.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/empty.cc b/libstdc++-v3/testsuite/std/ranges/access/empty.cc index 64b1e1b5e1b..9d6aa282142 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/empty.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/empty.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/end.cc b/libstdc++-v3/testsuite/std/ranges/access/end.cc index 6638bb35721..ed269c5433f 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/end.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/end.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include // N.B. should be +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc b/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc index a2a8fb05f92..0b40d274567 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/end_neg.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do compile { target c++2a } } -#include // N.B. should be +#include extern int unbounded[]; diff --git a/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc b/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc index 6cfc1a38122..067ddd7ced6 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/rbegin.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/rend.cc b/libstdc++-v3/testsuite/std/ranges/access/rend.cc index 2192825708a..17caa9fb31a 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/rend.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/rend.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/size.cc b/libstdc++-v3/testsuite/std/ranges/access/size.cc index b0a27ca2a87..6e9af7942ec 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/size.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/size.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } -#include +#include #include #include diff --git a/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc b/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc index 0ba8d81874f..65fce104ff6 100644 --- a/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc +++ b/libstdc++-v3/testsuite/std/ranges/access/size_neg.cc @@ -18,7 +18,7 @@ // { dg-options "-std=gnu++2a" } // { dg-do compile { target c++2a } } -#include // N.B. should be +#include extern int unbounded[]; diff --git a/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc b/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc new file mode 100644 index 00000000000..d4596cc8db5 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +struct R { }; +template<> constexpr bool std::ranges::disable_sized_range = true; + +namespace __gnu_test +{ + constexpr const bool* disable_sized_range + = &std::ranges::disable_sized_range; + constexpr auto* begin = &std::ranges::begin; + constexpr auto* end = &std::ranges::end; + constexpr auto* cbegin = &std::ranges::cbegin; + constexpr auto* cend = &std::ranges::cend; + constexpr auto* rbegin = &std::ranges::rbegin; + constexpr auto* rend = &std::ranges::rend; + constexpr auto* crbegin = &std::ranges::crbegin; + constexpr auto* crend = &std::ranges::crend; +} diff --git a/libstdc++-v3/testsuite/std/ranges/range.cc b/libstdc++-v3/testsuite/std/ranges/range.cc new file mode 100644 index 00000000000..44869de3ffb --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/range.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +static_assert( std::ranges::range ); +static_assert( std::ranges::range ); +static_assert( std::ranges::range ); +static_assert( !std::ranges::range ); + +using namespace __gnu_test; + +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); + +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); +static_assert( std::ranges::range> ); +static_assert( std::ranges::range&> ); + +using std::same_as; + +using C = test_contiguous_range; +using I = test_input_range; +using O = test_output_range; + +static_assert( same_as, + contiguous_iterator_wrapper> ); +static_assert( same_as, + decltype(std::declval().begin())> ); + +static_assert( same_as, + contiguous_iterator_wrapper> ); +static_assert( same_as, + decltype(std::declval().end())> ); + +static_assert( same_as, + std::ptrdiff_t> ); +static_assert( same_as, + std::ptrdiff_t> ); + +static_assert( same_as, + char> ); + +static_assert( same_as, + char&> ); +static_assert( same_as, + WritableObject> ); + +static_assert( same_as, + char&&> ); +static_assert( same_as, + WritableObject> ); diff --git a/libstdc++-v3/testsuite/std/ranges/refinements.cc b/libstdc++-v3/testsuite/std/ranges/refinements.cc new file mode 100644 index 00000000000..0b315397944 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/refinements.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +static_assert( std::ranges::output_range ); +static_assert( ! std::ranges::output_range ); +static_assert( std::ranges::output_range ); +static_assert( ! std::ranges::output_range ); + +static_assert( std::ranges::input_range ); +static_assert( std::ranges::input_range ); +static_assert( std::ranges::input_range ); + +static_assert( std::ranges::contiguous_range ); +static_assert( std::ranges::contiguous_range ); +static_assert( std::ranges::contiguous_range ); + +using namespace __gnu_test; + +static_assert( std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); +static_assert( ! std::ranges::output_range, int> ); +static_assert( std::ranges::output_range, int> ); + +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( std::ranges::input_range> ); +static_assert( ! std::ranges::input_range> ); + +static_assert( std::ranges::forward_range> ); +static_assert( std::ranges::forward_range> ); +static_assert( std::ranges::forward_range> ); +static_assert( std::ranges::forward_range> ); +static_assert( ! std::ranges::forward_range> ); +static_assert( ! std::ranges::forward_range> ); + +static_assert( std::ranges::bidirectional_range> ); +static_assert( std::ranges::bidirectional_range>); +static_assert( std::ranges::bidirectional_range>); +static_assert( ! std::ranges::bidirectional_range> ); +static_assert( ! std::ranges::bidirectional_range> ); +static_assert( ! std::ranges::bidirectional_range> ); + +static_assert( std::ranges::random_access_range> ); +static_assert( std::ranges::random_access_range>); +static_assert( ! std::ranges::random_access_range>); +static_assert( ! std::ranges::random_access_range> ); +static_assert( ! std::ranges::random_access_range> ); +static_assert( ! std::ranges::random_access_range> ); + +static_assert( std::ranges::contiguous_range> ); +static_assert( ! std::ranges::contiguous_range>); +static_assert( ! std::ranges::contiguous_range>); +static_assert( ! std::ranges::contiguous_range> ); +static_assert( ! std::ranges::contiguous_range> ); +static_assert( ! std::ranges::contiguous_range> ); diff --git a/libstdc++-v3/testsuite/std/ranges/sized.cc b/libstdc++-v3/testsuite/std/ranges/sized.cc new file mode 100644 index 00000000000..dd685c7a674 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/sized.cc @@ -0,0 +1,75 @@ +// Copyright (C) 2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +static_assert( std::ranges::sized_range ); +static_assert( std::ranges::sized_range ); +static_assert( std::ranges::sized_range ); +static_assert( !std::ranges::sized_range ); + +using namespace __gnu_test; + +// ranges::size(r) uses (end(r) - begin(r)) +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +// ranges::size(r) is invalid, (end(r) - begin(r)) requires sized sentinel +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); +static_assert(!std::ranges::sized_range> ); +static_assert(!std::ranges::sized_range&> ); + +// ranges::size(r) uses r.size() +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); +static_assert( std::ranges::sized_range> ); +static_assert( std::ranges::sized_range&> ); + +using long_range = __gnu_test::test_random_access_sized_range; +template<> constexpr bool std::ranges::disable_sized_range = true; + +// Despite being disabled, this is still a sized_range because ranges::size(r) +// works, by using (ranges::end(r) - ranges::begin(r)). +static_assert( std::ranges::sized_range ); +static_assert( std::ranges::sized_range ); + +using short_range = __gnu_test::test_bidirectional_sized_range; +template<> constexpr bool std::ranges::disable_sized_range = true; + +// This is not a sized range because ranges::size(r) cannot use member size, +// or ADL size, and (ranges::end(r) - ranges::begin(r)) is ill-formed for +// bidirectional iterators. +static_assert( !std::ranges::sized_range ); +static_assert( !std::ranges::sized_range ); diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index c5ae5b123fe..d20257c1b31 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -95,7 +95,7 @@ namespace __gnu_test #if __cplusplus >= 201103L template typename std::enable_if::value>::type - operator=(U&& new_val) + operator=(U&& new_val) const { ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0); SharedInfo->writtento[ptr - SharedInfo->first] = 1; @@ -720,6 +720,25 @@ namespace __gnu_test typename Iter::ContainerType bounds; }; + template + using test_contiguous_range + = test_range; + template + using test_random_access_range + = test_range; + template + using test_bidirectional_range + = test_range; + template + using test_forward_range + = test_range; + template + using test_input_range + = test_range; + template + using test_output_range + = test_range; + // A type meeting the minimum std::sized_range requirements template class Iter> struct test_sized_range : test_range @@ -729,6 +748,25 @@ namespace __gnu_test std::size_t size() const noexcept { return this->bounds.size(); } }; + + template + using test_contiguous_sized_range + = test_sized_range; + template + using test_random_access_sized_range + = test_sized_range; + template + using test_bidirectional_sized_range + = test_sized_range; + template + using test_forward_sized_range + = test_sized_range; + template + using test_input_sized_range + = test_sized_range; + template + using test_output_sized_range + = test_sized_range; #endif // C++20 } // namespace __gnu_test #endif // _TESTSUITE_ITERATORS