2019-10-11 17:53:52 +02:00
|
|
|
// <concepts> -*- C++ -*-
|
|
|
|
|
2021-01-04 10:26:59 +01:00
|
|
|
// Copyright (C) 2019-2021 Free Software Foundation, Inc.
|
2019-10-11 17:53:52 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2020-10-15 20:19:15 +02:00
|
|
|
// 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;
|
2019-10-11 17:53:52 +02:00
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/** @file include/concepts
|
2019-10-16 12:26:05 +02:00
|
|
|
* This is a Standard C++ Library header.
|
2019-10-11 17:53:52 +02:00
|
|
|
* @ingroup concepts
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GLIBCXX_CONCEPTS
|
|
|
|
#define _GLIBCXX_CONCEPTS 1
|
|
|
|
|
2020-03-28 00:21:58 +01:00
|
|
|
#if __cplusplus > 201703L && __cpp_concepts >= 201907L
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
#pragma GCC system_header
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup concepts Concepts
|
|
|
|
* @ingroup utilities
|
|
|
|
*
|
|
|
|
* Concepts for checking type requirements.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
|
|
{
|
|
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
|
|
2020-04-22 23:54:34 +02:00
|
|
|
#define __cpp_lib_concepts 202002L
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
// [concepts.lang], language-related concepts
|
|
|
|
|
|
|
|
namespace __detail
|
|
|
|
{
|
|
|
|
template<typename _Tp, typename _Up>
|
2019-10-16 12:26:05 +02:00
|
|
|
concept __same_as = std::is_same_v<_Tp, _Up>;
|
2019-10-11 17:53:52 +02:00
|
|
|
} // namespace __detail
|
|
|
|
|
|
|
|
/// [concept.same], concept same_as
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept same_as
|
|
|
|
= __detail::__same_as<_Tp, _Up> && __detail::__same_as<_Up, _Tp>;
|
|
|
|
|
|
|
|
/// [concept.derived], concept derived_from
|
|
|
|
template<typename _Derived, typename _Base>
|
|
|
|
concept derived_from = __is_base_of(_Base, _Derived)
|
|
|
|
&& is_convertible_v<const volatile _Derived*, const volatile _Base*>;
|
|
|
|
|
|
|
|
/// [concept.convertible], concept convertible_to
|
|
|
|
template<typename _From, typename _To>
|
|
|
|
concept convertible_to = is_convertible_v<_From, _To>
|
2021-06-18 17:51:33 +02:00
|
|
|
&& requires { static_cast<_To>(std::declval<_From>()); };
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
/// [concept.commonref], concept common_reference_with
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept common_reference_with
|
|
|
|
= same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>>
|
|
|
|
&& convertible_to<_Tp, common_reference_t<_Tp, _Up>>
|
|
|
|
&& convertible_to<_Up, common_reference_t<_Tp, _Up>>;
|
|
|
|
|
|
|
|
/// [concept.common], concept common_with
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept common_with
|
|
|
|
= same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>>
|
|
|
|
&& requires {
|
|
|
|
static_cast<common_type_t<_Tp, _Up>>(std::declval<_Tp>());
|
|
|
|
static_cast<common_type_t<_Tp, _Up>>(std::declval<_Up>());
|
|
|
|
}
|
|
|
|
&& common_reference_with<add_lvalue_reference_t<const _Tp>,
|
|
|
|
add_lvalue_reference_t<const _Up>>
|
|
|
|
&& common_reference_with<add_lvalue_reference_t<common_type_t<_Tp, _Up>>,
|
|
|
|
common_reference_t<
|
|
|
|
add_lvalue_reference_t<const _Tp>,
|
|
|
|
add_lvalue_reference_t<const _Up>>>;
|
|
|
|
|
|
|
|
// [concepts.arithmetic], arithmetic concepts
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept integral = is_integral_v<_Tp>;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept floating_point = is_floating_point_v<_Tp>;
|
|
|
|
|
|
|
|
namespace __detail
|
|
|
|
{
|
|
|
|
template<typename _Tp>
|
|
|
|
using __cref = const remove_reference_t<_Tp>&;
|
Add iterator concepts and range access customization points for C++20
This adds most of the new C++20 features to <iterator>, as well as a few
initial pieces of <ranges> (but no actual <ranges> header just yet).
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/iterator_concepts.h: New header.
(contiguous_iterator_tag, iter_reference_t, ranges::iter_move)
(iter_rvalue_reference_t, incrementable_traits, iter_difference_t)
(readable_traits, iter_value_t, readable, iter_common_reference_t)
(writable, waekly_incrementable, incrementable)
(input_or_output_iterator, sentinel_for, disable_sized_sentinel)
(sized_sentinel_for, input_iterator, output_iterator)
(forward_iterator, bidirectional_iterator, random_access_iterator)
(contiguous_iterator, indirectly_unary_invocable)
(indirectly_regular_unary_invocable, indirect_unary_predicate)
(indirect_relation, indirect_strict_weak_order, indirect_result_t)
(projected, indirectly_movable, indirectly_movable_storable)
(indirectly_copyable, indirectly_copyable_storable, ranges::iter_swap)
(indirectly_swappable, indirectly_comparable, permutable, mergeable)
(sortable, unreachable_sentinel_t, unreachable_sentinel)
(default_sentinel_t, default_sentinel): Define.
(__detail::__cpp17_iterator, __detail::__cpp17_input_iterator)
(__detail::__cpp17_fwd_iterator, __detail::__cpp17_bidi_iterator)
(__detail::__cpp17_randacc_iterator): Define.
(__iterator_traits): Define constrained specializations.
* include/bits/move.h (move): Only use old concept check for C++98.
* include/bits/range_access.h (ranges::disable_sized_range)
(ranges::begin, ranges::end, ranges::cbegin, ranges::cend)
(ranges::rbegin, ranges::rend, ranges::crbegin, ranges::crend)
(ranges::size, ranges::empty, ranges::data, ranges::cdata): Define
new customization points for C++20.
(ranges::range, ranges::sized_range): Define new concepts for C++20.
(ranges::advance, ranges::distance, ranges::next, ranges::prev):
Define new functions for C++20.
(__adl_end, __adl_cdata, __adl_cbegin, __adl_cend, __adl_rbegin)
(__adl_rend, __adl_crbegin, __adl_crend, __adl_cdata, __adl_size)
(__adl_empty): Remove.
* include/bits/stl_iterator.h (disable_sized_sentinel): Specialize
for reverse_iterator.
* include/bits/stl_iterator_base_types.h (contiguous_iterator_tag):
Define new struct for C++20.
(iterator_traits<_Tp*>): Constrain partial specialization in C++20.
* include/std/concepts (__is_class_or_enum): Move to __detail
namespace.
* testsuite/20_util/forward/c_neg.cc: Adjust dg-error line number.
* testsuite/20_util/forward/f_neg.cc: Likewise.
* testsuite/24_iterators/associated_types/incrementable.traits.cc: New
test.
* testsuite/24_iterators/associated_types/readable.traits.cc: New test.
* testsuite/24_iterators/contiguous/concept.cc: New test.
* testsuite/24_iterators/contiguous/tag.cc: New test.
* testsuite/24_iterators/customization_points/iter_move.cc: New test.
* testsuite/24_iterators/customization_points/iter_swap.cc: New test.
* testsuite/24_iterators/headers/iterator/synopsis_c++20.cc: New test.
* testsuite/24_iterators/range_operations/advance.cc: New test.
* testsuite/24_iterators/range_operations/distance.cc: New test.
* testsuite/24_iterators/range_operations/next.cc: New test.
* testsuite/24_iterators/range_operations/prev.cc: New test.
* testsuite/26_numerics/adjacent_difference/requirements/
explicit_instantiation/2.cc: Rename types that conflict with C++20
concepts.
* testsuite/26_numerics/adjacent_difference/requirements/
explicit_instantiation/pod.cc: Likewise.
* testsuite/26_numerics/partial_sum/requirements/
explicit_instantiation/2.cc: Likewise.
* testsuite/26_numerics/partial_sum/requirements/
explicit_instantiation/pod.cc: Likewise.
* testsuite/experimental/iterator/requirements.cc: Likewise.
* testsuite/std/ranges/access/begin.cc: New test.
* testsuite/std/ranges/access/cbegin.cc: New test.
* testsuite/std/ranges/access/cdata.cc: New test.
* testsuite/std/ranges/access/cend.cc: New test.
* testsuite/std/ranges/access/crbegin.cc: New test.
* testsuite/std/ranges/access/crend.cc: New test.
* testsuite/std/ranges/access/data.cc: New test.
* testsuite/std/ranges/access/empty.cc: New test.
* testsuite/std/ranges/access/end.cc: New test.
* testsuite/std/ranges/access/rbegin.cc: New test.
* testsuite/std/ranges/access/rend.cc: New test.
* testsuite/std/ranges/access/size.cc: New test.
* testsuite/util/testsuite_iterators.h (contiguous_iterator_wrapper)
(test_range, test_sized_range): New test utilities.
From-SVN: r277579
2019-10-29 18:44:18 +01:00
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept __class_or_enum
|
|
|
|
= is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
|
2019-10-11 17:53:52 +02:00
|
|
|
} // namespace __detail
|
|
|
|
|
|
|
|
/// [concept.assignable], concept assignable_from
|
|
|
|
template<typename _Lhs, typename _Rhs>
|
|
|
|
concept assignable_from
|
|
|
|
= is_lvalue_reference_v<_Lhs>
|
|
|
|
&& common_reference_with<__detail::__cref<_Lhs>, __detail::__cref<_Rhs>>
|
|
|
|
&& requires(_Lhs __lhs, _Rhs&& __rhs) {
|
|
|
|
{ __lhs = static_cast<_Rhs&&>(__rhs) } -> same_as<_Lhs>;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// [concept.destructible], concept destructible
|
|
|
|
template<typename _Tp>
|
|
|
|
concept destructible = is_nothrow_destructible_v<_Tp>;
|
|
|
|
|
|
|
|
/// [concept.constructible], concept constructible_from
|
|
|
|
template<typename _Tp, typename... _Args>
|
|
|
|
concept constructible_from
|
|
|
|
= destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
|
|
|
|
|
2019-11-15 20:58:27 +01:00
|
|
|
/// [concept.defaultinitializable], concept default_initializable
|
2019-10-11 17:53:52 +02:00
|
|
|
template<typename _Tp>
|
2019-11-15 20:58:27 +01:00
|
|
|
concept default_initializable = constructible_from<_Tp>
|
|
|
|
&& requires
|
|
|
|
{
|
|
|
|
_Tp{};
|
|
|
|
(void) ::new _Tp;
|
|
|
|
};
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
/// [concept.moveconstructible], concept move_constructible
|
|
|
|
template<typename _Tp>
|
|
|
|
concept move_constructible
|
|
|
|
= constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
|
|
|
|
|
|
|
|
/// [concept.copyconstructible], concept copy_constructible
|
|
|
|
template<typename _Tp>
|
|
|
|
concept copy_constructible
|
|
|
|
= move_constructible<_Tp>
|
|
|
|
&& constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp>
|
|
|
|
&& constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp>
|
|
|
|
&& constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
|
|
|
|
|
|
|
|
// [concept.swappable], concept swappable
|
|
|
|
|
|
|
|
namespace ranges
|
|
|
|
{
|
|
|
|
namespace __cust_swap
|
|
|
|
{
|
|
|
|
template<typename _Tp> void swap(_Tp&, _Tp&) = delete;
|
|
|
|
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept __adl_swap
|
Add iterator concepts and range access customization points for C++20
This adds most of the new C++20 features to <iterator>, as well as a few
initial pieces of <ranges> (but no actual <ranges> header just yet).
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/iterator_concepts.h: New header.
(contiguous_iterator_tag, iter_reference_t, ranges::iter_move)
(iter_rvalue_reference_t, incrementable_traits, iter_difference_t)
(readable_traits, iter_value_t, readable, iter_common_reference_t)
(writable, waekly_incrementable, incrementable)
(input_or_output_iterator, sentinel_for, disable_sized_sentinel)
(sized_sentinel_for, input_iterator, output_iterator)
(forward_iterator, bidirectional_iterator, random_access_iterator)
(contiguous_iterator, indirectly_unary_invocable)
(indirectly_regular_unary_invocable, indirect_unary_predicate)
(indirect_relation, indirect_strict_weak_order, indirect_result_t)
(projected, indirectly_movable, indirectly_movable_storable)
(indirectly_copyable, indirectly_copyable_storable, ranges::iter_swap)
(indirectly_swappable, indirectly_comparable, permutable, mergeable)
(sortable, unreachable_sentinel_t, unreachable_sentinel)
(default_sentinel_t, default_sentinel): Define.
(__detail::__cpp17_iterator, __detail::__cpp17_input_iterator)
(__detail::__cpp17_fwd_iterator, __detail::__cpp17_bidi_iterator)
(__detail::__cpp17_randacc_iterator): Define.
(__iterator_traits): Define constrained specializations.
* include/bits/move.h (move): Only use old concept check for C++98.
* include/bits/range_access.h (ranges::disable_sized_range)
(ranges::begin, ranges::end, ranges::cbegin, ranges::cend)
(ranges::rbegin, ranges::rend, ranges::crbegin, ranges::crend)
(ranges::size, ranges::empty, ranges::data, ranges::cdata): Define
new customization points for C++20.
(ranges::range, ranges::sized_range): Define new concepts for C++20.
(ranges::advance, ranges::distance, ranges::next, ranges::prev):
Define new functions for C++20.
(__adl_end, __adl_cdata, __adl_cbegin, __adl_cend, __adl_rbegin)
(__adl_rend, __adl_crbegin, __adl_crend, __adl_cdata, __adl_size)
(__adl_empty): Remove.
* include/bits/stl_iterator.h (disable_sized_sentinel): Specialize
for reverse_iterator.
* include/bits/stl_iterator_base_types.h (contiguous_iterator_tag):
Define new struct for C++20.
(iterator_traits<_Tp*>): Constrain partial specialization in C++20.
* include/std/concepts (__is_class_or_enum): Move to __detail
namespace.
* testsuite/20_util/forward/c_neg.cc: Adjust dg-error line number.
* testsuite/20_util/forward/f_neg.cc: Likewise.
* testsuite/24_iterators/associated_types/incrementable.traits.cc: New
test.
* testsuite/24_iterators/associated_types/readable.traits.cc: New test.
* testsuite/24_iterators/contiguous/concept.cc: New test.
* testsuite/24_iterators/contiguous/tag.cc: New test.
* testsuite/24_iterators/customization_points/iter_move.cc: New test.
* testsuite/24_iterators/customization_points/iter_swap.cc: New test.
* testsuite/24_iterators/headers/iterator/synopsis_c++20.cc: New test.
* testsuite/24_iterators/range_operations/advance.cc: New test.
* testsuite/24_iterators/range_operations/distance.cc: New test.
* testsuite/24_iterators/range_operations/next.cc: New test.
* testsuite/24_iterators/range_operations/prev.cc: New test.
* testsuite/26_numerics/adjacent_difference/requirements/
explicit_instantiation/2.cc: Rename types that conflict with C++20
concepts.
* testsuite/26_numerics/adjacent_difference/requirements/
explicit_instantiation/pod.cc: Likewise.
* testsuite/26_numerics/partial_sum/requirements/
explicit_instantiation/2.cc: Likewise.
* testsuite/26_numerics/partial_sum/requirements/
explicit_instantiation/pod.cc: Likewise.
* testsuite/experimental/iterator/requirements.cc: Likewise.
* testsuite/std/ranges/access/begin.cc: New test.
* testsuite/std/ranges/access/cbegin.cc: New test.
* testsuite/std/ranges/access/cdata.cc: New test.
* testsuite/std/ranges/access/cend.cc: New test.
* testsuite/std/ranges/access/crbegin.cc: New test.
* testsuite/std/ranges/access/crend.cc: New test.
* testsuite/std/ranges/access/data.cc: New test.
* testsuite/std/ranges/access/empty.cc: New test.
* testsuite/std/ranges/access/end.cc: New test.
* testsuite/std/ranges/access/rbegin.cc: New test.
* testsuite/std/ranges/access/rend.cc: New test.
* testsuite/std/ranges/access/size.cc: New test.
* testsuite/util/testsuite_iterators.h (contiguous_iterator_wrapper)
(test_range, test_sized_range): New test utilities.
From-SVN: r277579
2019-10-29 18:44:18 +01:00
|
|
|
= (__detail::__class_or_enum<remove_reference_t<_Tp>>
|
|
|
|
|| __detail::__class_or_enum<remove_reference_t<_Up>>)
|
2019-10-11 17:53:52 +02:00
|
|
|
&& requires(_Tp&& __t, _Up&& __u) {
|
|
|
|
swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u));
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _Swap
|
|
|
|
{
|
2019-10-30 18:42:04 +01:00
|
|
|
private:
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
static constexpr bool
|
|
|
|
_S_noexcept()
|
|
|
|
{
|
|
|
|
if constexpr (__adl_swap<_Tp, _Up>)
|
|
|
|
return noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()));
|
|
|
|
else
|
|
|
|
return is_nothrow_move_constructible_v<remove_reference_t<_Tp>>
|
|
|
|
&& is_nothrow_move_assignable_v<remove_reference_t<_Tp>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2019-10-11 17:53:52 +02:00
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
requires __adl_swap<_Tp, _Up>
|
2019-10-30 18:42:04 +01:00
|
|
|
|| (same_as<_Tp, _Up> && is_lvalue_reference_v<_Tp>
|
|
|
|
&& move_constructible<remove_reference_t<_Tp>>
|
|
|
|
&& assignable_from<_Tp, remove_reference_t<_Tp>>)
|
Add iterator concepts and range access customization points for C++20
This adds most of the new C++20 features to <iterator>, as well as a few
initial pieces of <ranges> (but no actual <ranges> header just yet).
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/iterator_concepts.h: New header.
(contiguous_iterator_tag, iter_reference_t, ranges::iter_move)
(iter_rvalue_reference_t, incrementable_traits, iter_difference_t)
(readable_traits, iter_value_t, readable, iter_common_reference_t)
(writable, waekly_incrementable, incrementable)
(input_or_output_iterator, sentinel_for, disable_sized_sentinel)
(sized_sentinel_for, input_iterator, output_iterator)
(forward_iterator, bidirectional_iterator, random_access_iterator)
(contiguous_iterator, indirectly_unary_invocable)
(indirectly_regular_unary_invocable, indirect_unary_predicate)
(indirect_relation, indirect_strict_weak_order, indirect_result_t)
(projected, indirectly_movable, indirectly_movable_storable)
(indirectly_copyable, indirectly_copyable_storable, ranges::iter_swap)
(indirectly_swappable, indirectly_comparable, permutable, mergeable)
(sortable, unreachable_sentinel_t, unreachable_sentinel)
(default_sentinel_t, default_sentinel): Define.
(__detail::__cpp17_iterator, __detail::__cpp17_input_iterator)
(__detail::__cpp17_fwd_iterator, __detail::__cpp17_bidi_iterator)
(__detail::__cpp17_randacc_iterator): Define.
(__iterator_traits): Define constrained specializations.
* include/bits/move.h (move): Only use old concept check for C++98.
* include/bits/range_access.h (ranges::disable_sized_range)
(ranges::begin, ranges::end, ranges::cbegin, ranges::cend)
(ranges::rbegin, ranges::rend, ranges::crbegin, ranges::crend)
(ranges::size, ranges::empty, ranges::data, ranges::cdata): Define
new customization points for C++20.
(ranges::range, ranges::sized_range): Define new concepts for C++20.
(ranges::advance, ranges::distance, ranges::next, ranges::prev):
Define new functions for C++20.
(__adl_end, __adl_cdata, __adl_cbegin, __adl_cend, __adl_rbegin)
(__adl_rend, __adl_crbegin, __adl_crend, __adl_cdata, __adl_size)
(__adl_empty): Remove.
* include/bits/stl_iterator.h (disable_sized_sentinel): Specialize
for reverse_iterator.
* include/bits/stl_iterator_base_types.h (contiguous_iterator_tag):
Define new struct for C++20.
(iterator_traits<_Tp*>): Constrain partial specialization in C++20.
* include/std/concepts (__is_class_or_enum): Move to __detail
namespace.
* testsuite/20_util/forward/c_neg.cc: Adjust dg-error line number.
* testsuite/20_util/forward/f_neg.cc: Likewise.
* testsuite/24_iterators/associated_types/incrementable.traits.cc: New
test.
* testsuite/24_iterators/associated_types/readable.traits.cc: New test.
* testsuite/24_iterators/contiguous/concept.cc: New test.
* testsuite/24_iterators/contiguous/tag.cc: New test.
* testsuite/24_iterators/customization_points/iter_move.cc: New test.
* testsuite/24_iterators/customization_points/iter_swap.cc: New test.
* testsuite/24_iterators/headers/iterator/synopsis_c++20.cc: New test.
* testsuite/24_iterators/range_operations/advance.cc: New test.
* testsuite/24_iterators/range_operations/distance.cc: New test.
* testsuite/24_iterators/range_operations/next.cc: New test.
* testsuite/24_iterators/range_operations/prev.cc: New test.
* testsuite/26_numerics/adjacent_difference/requirements/
explicit_instantiation/2.cc: Rename types that conflict with C++20
concepts.
* testsuite/26_numerics/adjacent_difference/requirements/
explicit_instantiation/pod.cc: Likewise.
* testsuite/26_numerics/partial_sum/requirements/
explicit_instantiation/2.cc: Likewise.
* testsuite/26_numerics/partial_sum/requirements/
explicit_instantiation/pod.cc: Likewise.
* testsuite/experimental/iterator/requirements.cc: Likewise.
* testsuite/std/ranges/access/begin.cc: New test.
* testsuite/std/ranges/access/cbegin.cc: New test.
* testsuite/std/ranges/access/cdata.cc: New test.
* testsuite/std/ranges/access/cend.cc: New test.
* testsuite/std/ranges/access/crbegin.cc: New test.
* testsuite/std/ranges/access/crend.cc: New test.
* testsuite/std/ranges/access/data.cc: New test.
* testsuite/std/ranges/access/empty.cc: New test.
* testsuite/std/ranges/access/end.cc: New test.
* testsuite/std/ranges/access/rbegin.cc: New test.
* testsuite/std/ranges/access/rend.cc: New test.
* testsuite/std/ranges/access/size.cc: New test.
* testsuite/util/testsuite_iterators.h (contiguous_iterator_wrapper)
(test_range, test_sized_range): New test utilities.
From-SVN: r277579
2019-10-29 18:44:18 +01:00
|
|
|
constexpr void
|
|
|
|
operator()(_Tp&& __t, _Up&& __u) const
|
2019-10-30 18:42:04 +01:00
|
|
|
noexcept(_S_noexcept<_Tp, _Up>())
|
|
|
|
{
|
|
|
|
if constexpr (__adl_swap<_Tp, _Up>)
|
|
|
|
swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto __tmp = static_cast<remove_reference_t<_Tp>&&>(__t);
|
|
|
|
__t = static_cast<remove_reference_t<_Tp>&&>(__u);
|
|
|
|
__u = static_cast<remove_reference_t<_Tp>&&>(__tmp);
|
|
|
|
}
|
|
|
|
}
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
template<typename _Tp, typename _Up, size_t _Num>
|
|
|
|
requires requires(const _Swap& __swap, _Tp& __e1, _Up& __e2) {
|
|
|
|
__swap(__e1, __e2);
|
|
|
|
}
|
|
|
|
constexpr void
|
|
|
|
operator()(_Tp (&__e1)[_Num], _Up (&__e2)[_Num]) const
|
|
|
|
noexcept(noexcept(std::declval<const _Swap&>()(*__e1, *__e2)))
|
|
|
|
{
|
|
|
|
for (size_t __n = 0; __n < _Num; ++__n)
|
|
|
|
(*this)(__e1[__n], __e2[__n]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace __cust_swap
|
|
|
|
|
|
|
|
inline namespace __cust
|
|
|
|
{
|
|
|
|
inline constexpr __cust_swap::_Swap swap{};
|
|
|
|
} // inline namespace __cust
|
|
|
|
} // namespace ranges
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept swappable
|
|
|
|
= requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); };
|
|
|
|
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept swappable_with = common_reference_with<_Tp, _Up>
|
|
|
|
&& requires(_Tp&& __t, _Up&& __u) {
|
|
|
|
ranges::swap(static_cast<_Tp&&>(__t), static_cast<_Tp&&>(__t));
|
|
|
|
ranges::swap(static_cast<_Up&&>(__u), static_cast<_Up&&>(__u));
|
|
|
|
ranges::swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u));
|
|
|
|
ranges::swap(static_cast<_Up&&>(__u), static_cast<_Tp&&>(__t));
|
|
|
|
};
|
|
|
|
|
|
|
|
// [concepts.object], Object concepts
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept movable = is_object_v<_Tp> && move_constructible<_Tp>
|
|
|
|
&& assignable_from<_Tp&, _Tp> && swappable<_Tp>;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept copyable = copy_constructible<_Tp> && movable<_Tp>
|
2020-02-17 14:20:57 +01:00
|
|
|
&& assignable_from<_Tp&, _Tp&> && assignable_from<_Tp&, const _Tp&>
|
|
|
|
&& assignable_from<_Tp&, const _Tp>;
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
template<typename _Tp>
|
2019-11-15 20:58:27 +01:00
|
|
|
concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
// [concepts.compare], comparison concepts
|
|
|
|
|
2020-02-17 19:15:00 +01:00
|
|
|
// [concept.booleantestable], Boolean testability
|
|
|
|
namespace __detail
|
|
|
|
{
|
|
|
|
template<typename _Tp>
|
|
|
|
concept __boolean_testable_impl = convertible_to<_Tp, bool>;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept __boolean_testable
|
|
|
|
= __boolean_testable_impl<_Tp>
|
|
|
|
&& requires(_Tp&& __t)
|
|
|
|
{ { !static_cast<_Tp&&>(__t) } -> __boolean_testable_impl; };
|
|
|
|
} // namespace __detail
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
// [concept.equalitycomparable], concept equality_comparable
|
|
|
|
|
|
|
|
namespace __detail
|
|
|
|
{
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept __weakly_eq_cmp_with
|
|
|
|
= requires(__detail::__cref<_Tp> __t, __detail::__cref<_Up> __u) {
|
2020-02-17 19:15:00 +01:00
|
|
|
{ __t == __u } -> __boolean_testable;
|
|
|
|
{ __t != __u } -> __boolean_testable;
|
|
|
|
{ __u == __t } -> __boolean_testable;
|
|
|
|
{ __u != __t } -> __boolean_testable;
|
2019-10-11 17:53:52 +02:00
|
|
|
};
|
|
|
|
} // namespace __detail
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept equality_comparable = __detail::__weakly_eq_cmp_with<_Tp, _Tp>;
|
|
|
|
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept equality_comparable_with
|
|
|
|
= equality_comparable<_Tp> && equality_comparable<_Up>
|
|
|
|
&& common_reference_with<__detail::__cref<_Tp>, __detail::__cref<_Up>>
|
|
|
|
&& equality_comparable<common_reference_t<__detail::__cref<_Tp>,
|
|
|
|
__detail::__cref<_Up>>>
|
|
|
|
&& __detail::__weakly_eq_cmp_with<_Tp, _Up>;
|
|
|
|
|
2020-02-19 22:40:03 +01:00
|
|
|
namespace __detail
|
|
|
|
{
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept __partially_ordered_with
|
|
|
|
= requires(const remove_reference_t<_Tp>& __t,
|
|
|
|
const remove_reference_t<_Up>& __u) {
|
|
|
|
{ __t < __u } -> __boolean_testable;
|
|
|
|
{ __t > __u } -> __boolean_testable;
|
|
|
|
{ __t <= __u } -> __boolean_testable;
|
|
|
|
{ __t >= __u } -> __boolean_testable;
|
|
|
|
{ __u < __t } -> __boolean_testable;
|
|
|
|
{ __u > __t } -> __boolean_testable;
|
|
|
|
{ __u <= __t } -> __boolean_testable;
|
|
|
|
{ __u >= __t } -> __boolean_testable;
|
|
|
|
};
|
|
|
|
} // namespace __detail
|
|
|
|
|
2019-10-11 17:53:52 +02:00
|
|
|
// [concept.totallyordered], concept totally_ordered
|
|
|
|
template<typename _Tp>
|
|
|
|
concept totally_ordered
|
|
|
|
= equality_comparable<_Tp>
|
2020-02-19 22:40:03 +01:00
|
|
|
&& __detail::__partially_ordered_with<_Tp, _Tp>;
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
concept totally_ordered_with
|
|
|
|
= totally_ordered<_Tp> && totally_ordered<_Up>
|
2020-02-19 22:31:06 +01:00
|
|
|
&& equality_comparable_with<_Tp, _Up>
|
2019-10-11 17:53:52 +02:00
|
|
|
&& totally_ordered<common_reference_t<__detail::__cref<_Tp>,
|
|
|
|
__detail::__cref<_Up>>>
|
2020-02-19 22:40:03 +01:00
|
|
|
&& __detail::__partially_ordered_with<_Tp, _Up>;
|
2019-10-11 17:53:52 +02:00
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
|
|
|
|
|
|
|
|
// [concepts.callable], callable concepts
|
|
|
|
|
2019-11-14 17:53:18 +01:00
|
|
|
/// [concept.invocable], concept invocable
|
2019-10-11 17:53:52 +02:00
|
|
|
template<typename _Fn, typename... _Args>
|
|
|
|
concept invocable = is_invocable_v<_Fn, _Args...>;
|
|
|
|
|
2019-11-14 17:53:18 +01:00
|
|
|
/// [concept.regularinvocable], concept regular_invocable
|
2019-10-11 17:53:52 +02:00
|
|
|
template<typename _Fn, typename... _Args>
|
|
|
|
concept regular_invocable = invocable<_Fn, _Args...>;
|
|
|
|
|
2019-11-14 17:53:18 +01:00
|
|
|
/// [concept.predicate], concept predicate
|
2019-10-11 17:53:52 +02:00
|
|
|
template<typename _Fn, typename... _Args>
|
|
|
|
concept predicate = regular_invocable<_Fn, _Args...>
|
2020-02-17 19:15:00 +01:00
|
|
|
&& __detail::__boolean_testable<invoke_result_t<_Fn, _Args...>>;
|
2019-10-11 17:53:52 +02:00
|
|
|
|
2019-11-14 17:53:18 +01:00
|
|
|
/// [concept.relation], concept relation
|
2019-10-11 17:53:52 +02:00
|
|
|
template<typename _Rel, typename _Tp, typename _Up>
|
|
|
|
concept relation
|
|
|
|
= predicate<_Rel, _Tp, _Tp> && predicate<_Rel, _Up, _Up>
|
|
|
|
&& predicate<_Rel, _Tp, _Up> && predicate<_Rel, _Up, _Tp>;
|
|
|
|
|
2019-11-14 17:53:18 +01:00
|
|
|
/// [concept.equiv], concept equivalence_relation
|
|
|
|
template<typename _Rel, typename _Tp, typename _Up>
|
|
|
|
concept equivalence_relation = relation<_Rel, _Tp, _Up>;
|
|
|
|
|
|
|
|
/// [concept.strictweakorder], concept strict_weak_order
|
2019-10-11 17:53:52 +02:00
|
|
|
template<typename _Rel, typename _Tp, typename _Up>
|
|
|
|
concept strict_weak_order = relation<_Rel, _Tp, _Up>;
|
|
|
|
|
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
|
|
} // namespace
|
|
|
|
#endif // C++2a
|
|
|
|
|
|
|
|
#endif /* _GLIBCXX_CONCEPTS */
|