1// -*- C++ -*-
2//===-------------------------- concepts ----------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_CONCEPTS
11#define _LIBCPP_CONCEPTS
12
13/*
14    concepts synopsis
15namespace std {
16  // [concepts.lang], language-related concepts
17  // [concept.same], concept same_as
18  template<class T, class U>
19    concept same_as = see below;
20
21  // [concept.derived], concept derived_from
22  template<class Derived, class Base>
23    concept derived_from = see below;
24
25  // [concept.convertible], concept convertible_to
26  template<class From, class To>
27    concept convertible_to = see below;
28
29  // [concept.commonref], concept common_reference_with
30  template<class T, class U>
31    concept common_reference_with = see below;
32
33  // [concept.common], concept common_with
34  template<class T, class U>
35    concept common_with = see below;
36
37  // [concepts.arithmetic], arithmetic concepts
38  template<class T>
39    concept integral = see below;
40  template<class T>
41    concept signed_integral = see below;
42  template<class T>
43    concept unsigned_integral = see below;
44  template<class T>
45    concept floating_point = see below;
46
47  // [concept.assignable], concept assignable_from
48  template<class LHS, class RHS>
49    concept assignable_from = see below;
50
51  // [concept.swappable], concept swappable
52  namespace ranges {
53    inline namespace unspecified {
54      inline constexpr unspecified swap = unspecified;
55    }
56  }
57  template<class T>
58    concept swappable = see below;
59  template<class T, class U>
60    concept swappable_with = see below;
61
62  // [concept.destructible], concept destructible
63  template<class T>
64    concept destructible = see below;
65
66  // [concept.constructible], concept constructible_from
67  template<class T, class... Args>
68    concept constructible_from = see below;
69
70  // [concept.defaultconstructible], concept default_constructible
71  template<class T>
72    concept default_constructible = see below;
73
74  // [concept.moveconstructible], concept move_constructible
75  template<class T>
76    concept move_constructible = see below;
77
78  // [concept.copyconstructible], concept copy_constructible
79  template<class T>
80    concept copy_constructible = see below;
81
82  // [concepts.compare], comparison concepts
83  // [concept.boolean], concept boolean
84  template<class B>
85    concept boolean = see below;
86
87  // [concept.equalitycomparable], concept equality_comparable
88  template<class T>
89    concept equality_comparable = see below;
90  template<class T, class U>
91    concept equality_comparable_with = see below;
92
93  // [concept.totallyordered], concept totally_ordered
94  template<class T>
95    concept totally_ordered = see below;
96  template<class T, class U>
97    concept totally_ordered_with = see below;
98
99  // [concepts.object], object concepts
100  template<class T>
101    concept movable = see below;
102  template<class T>
103    concept copyable = see below;
104  template<class T>
105    concept semiregular = see below;
106  template<class T>
107    concept regular = see below;
108
109  // [concepts.callable], callable concepts
110  // [concept.invocable], concept invocable
111  template<class F, class... Args>
112    concept invocable = see below;
113
114  // [concept.regularinvocable], concept regular_invocable
115  template<class F, class... Args>
116    concept regular_invocable = see below;
117
118  // [concept.predicate], concept predicate
119  template<class F, class... Args>
120    concept predicate = see below;
121
122  // [concept.relation], concept relation
123  template<class R, class T, class U>
124    concept relation = see below;
125
126  // [concept.equiv], concept equivalence_relation
127  template<class R, class T, class U>
128    concept equivalence_relation = see below;
129
130  // [concept.strictweakorder], concept strict_weak_order
131  template<class R, class T, class U>
132    concept strict_weak_order = see below;
133}
134
135*/
136
137#include <__config>
138#include <functional>
139#include <type_traits>
140#include <utility>
141#include <version>
142
143#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
144#pragma GCC system_header
145#endif
146
147_LIBCPP_PUSH_MACROS
148#include <__undef_macros>
149
150_LIBCPP_BEGIN_NAMESPACE_STD
151
152#if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
153
154// [concept.same]
155
156template<class _Tp, class _Up>
157concept __same_as_impl = _VSTD::_IsSame<_Tp, _Up>::value;
158
159template<class _Tp, class _Up>
160concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
161
162// [concept.derived]
163template<class _Dp, class _Bp>
164concept derived_from =
165  is_base_of_v<_Bp, _Dp> &&
166  is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
167
168// [concept.convertible]
169template<class _From, class _To>
170concept convertible_to =
171  is_convertible_v<_From, _To> &&
172  requires(add_rvalue_reference_t<_From> (&__f)()) {
173    static_cast<_To>(__f());
174  };
175
176// [concepts.arithmetic], arithmetic concepts
177template<class _Tp>
178concept integral = is_integral_v<_Tp>;
179
180template<class _Tp>
181concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
182
183template<class _Tp>
184concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
185
186template<class _Tp>
187concept floating_point = is_floating_point_v<_Tp>;
188
189// [concept.destructible]
190
191template<class _Tp>
192concept destructible = _VSTD::is_nothrow_destructible_v<_Tp>;
193
194// [concept.constructible]
195template<class _Tp, class... _Args>
196concept constructible_from =
197    destructible<_Tp> && _VSTD::is_constructible_v<_Tp, _Args...>;
198
199// [concept.default.init]
200
201template<class _Tp>
202concept __default_initializable = requires { ::new _Tp; };
203
204template<class _Tp>
205concept default_initializable = constructible_from<_Tp> &&
206    requires { _Tp{}; } && __default_initializable<_Tp>;
207
208// [concept.moveconstructible]
209template<class _Tp>
210concept move_constructible =
211  constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
212
213// [concept.copyconstructible]
214template<class _Tp>
215concept copy_constructible =
216  move_constructible<_Tp> &&
217  constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
218  constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
219  constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
220
221// [concept.invocable]
222template<class _Fn, class... _Args>
223concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
224  _VSTD::invoke(_VSTD::forward<_Fn>(__fn), _VSTD::forward<_Args>(__args)...); // not required to be equality preserving
225};
226
227// [concept.regular.invocable]
228template<class _Fn, class... _Args>
229concept regular_invocable = invocable<_Fn, _Args...>;
230
231#endif //_LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L
232
233_LIBCPP_END_NAMESPACE_STD
234
235_LIBCPP_POP_MACROS
236
237#endif // _LIBCPP_CONCEPTS
238