1*38fd1498Szrj // -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj // Copyright (C) 2004-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj
25*38fd1498Szrj // (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
26*38fd1498Szrj // sell and distribute this software is granted provided this
27*38fd1498Szrj // copyright notice appears in all copies. This software is provided
28*38fd1498Szrj // "as is" without express or implied warranty, and with no claim as
29*38fd1498Szrj // to its suitability for any purpose.
30*38fd1498Szrj //
31*38fd1498Szrj
32*38fd1498Szrj /** @file bits/boost_concept_check.h
33*38fd1498Szrj * This is an internal header file, included by other library headers.
34*38fd1498Szrj * Do not attempt to use it directly. @headername{iterator}
35*38fd1498Szrj */
36*38fd1498Szrj
37*38fd1498Szrj // GCC Note: based on version 1.12.0 of the Boost library.
38*38fd1498Szrj
39*38fd1498Szrj #ifndef _BOOST_CONCEPT_CHECK_H
40*38fd1498Szrj #define _BOOST_CONCEPT_CHECK_H 1
41*38fd1498Szrj
42*38fd1498Szrj #pragma GCC system_header
43*38fd1498Szrj
44*38fd1498Szrj #include <bits/c++config.h>
45*38fd1498Szrj #include <bits/stl_iterator_base_types.h> // for traits and tags
46*38fd1498Szrj
_GLIBCXX_VISIBILITY(default)47*38fd1498Szrj namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
48*38fd1498Szrj {
49*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
50*38fd1498Szrj
51*38fd1498Szrj #pragma GCC diagnostic push
52*38fd1498Szrj #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
53*38fd1498Szrj
54*38fd1498Szrj #define _IsUnused __attribute__ ((__unused__))
55*38fd1498Szrj
56*38fd1498Szrj // When the C-C code is in use, we would like this function to do as little
57*38fd1498Szrj // as possible at runtime, use as few resources as possible, and hopefully
58*38fd1498Szrj // be elided out of existence... hmmm.
59*38fd1498Szrj template <class _Concept>
60*38fd1498Szrj inline void __function_requires()
61*38fd1498Szrj {
62*38fd1498Szrj void (_Concept::*__x)() _IsUnused = &_Concept::__constraints;
63*38fd1498Szrj }
64*38fd1498Szrj
65*38fd1498Szrj // No definition: if this is referenced, there's a problem with
66*38fd1498Szrj // the instantiating type not being one of the required integer types.
67*38fd1498Szrj // Unfortunately, this results in a link-time error, not a compile-time error.
68*38fd1498Szrj void __error_type_must_be_an_integer_type();
69*38fd1498Szrj void __error_type_must_be_an_unsigned_integer_type();
70*38fd1498Szrj void __error_type_must_be_a_signed_integer_type();
71*38fd1498Szrj
72*38fd1498Szrj // ??? Should the "concept_checking*" structs begin with more than _ ?
73*38fd1498Szrj #define _GLIBCXX_CLASS_REQUIRES(_type_var, _ns, _concept) \
74*38fd1498Szrj typedef void (_ns::_concept <_type_var>::* _func##_type_var##_concept)(); \
75*38fd1498Szrj template <_func##_type_var##_concept _Tp1> \
76*38fd1498Szrj struct _concept_checking##_type_var##_concept { }; \
77*38fd1498Szrj typedef _concept_checking##_type_var##_concept< \
78*38fd1498Szrj &_ns::_concept <_type_var>::__constraints> \
79*38fd1498Szrj _concept_checking_typedef##_type_var##_concept
80*38fd1498Szrj
81*38fd1498Szrj #define _GLIBCXX_CLASS_REQUIRES2(_type_var1, _type_var2, _ns, _concept) \
82*38fd1498Szrj typedef void (_ns::_concept <_type_var1,_type_var2>::* _func##_type_var1##_type_var2##_concept)(); \
83*38fd1498Szrj template <_func##_type_var1##_type_var2##_concept _Tp1> \
84*38fd1498Szrj struct _concept_checking##_type_var1##_type_var2##_concept { }; \
85*38fd1498Szrj typedef _concept_checking##_type_var1##_type_var2##_concept< \
86*38fd1498Szrj &_ns::_concept <_type_var1,_type_var2>::__constraints> \
87*38fd1498Szrj _concept_checking_typedef##_type_var1##_type_var2##_concept
88*38fd1498Szrj
89*38fd1498Szrj #define _GLIBCXX_CLASS_REQUIRES3(_type_var1, _type_var2, _type_var3, _ns, _concept) \
90*38fd1498Szrj typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3>::* _func##_type_var1##_type_var2##_type_var3##_concept)(); \
91*38fd1498Szrj template <_func##_type_var1##_type_var2##_type_var3##_concept _Tp1> \
92*38fd1498Szrj struct _concept_checking##_type_var1##_type_var2##_type_var3##_concept { }; \
93*38fd1498Szrj typedef _concept_checking##_type_var1##_type_var2##_type_var3##_concept< \
94*38fd1498Szrj &_ns::_concept <_type_var1,_type_var2,_type_var3>::__constraints> \
95*38fd1498Szrj _concept_checking_typedef##_type_var1##_type_var2##_type_var3##_concept
96*38fd1498Szrj
97*38fd1498Szrj #define _GLIBCXX_CLASS_REQUIRES4(_type_var1, _type_var2, _type_var3, _type_var4, _ns, _concept) \
98*38fd1498Szrj typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::* _func##_type_var1##_type_var2##_type_var3##_type_var4##_concept)(); \
99*38fd1498Szrj template <_func##_type_var1##_type_var2##_type_var3##_type_var4##_concept _Tp1> \
100*38fd1498Szrj struct _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept { }; \
101*38fd1498Szrj typedef _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept< \
102*38fd1498Szrj &_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::__constraints> \
103*38fd1498Szrj _concept_checking_typedef##_type_var1##_type_var2##_type_var3##_type_var4##_concept
104*38fd1498Szrj
105*38fd1498Szrj
106*38fd1498Szrj template <class _Tp1, class _Tp2>
107*38fd1498Szrj struct _Aux_require_same { };
108*38fd1498Szrj
109*38fd1498Szrj template <class _Tp>
110*38fd1498Szrj struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; };
111*38fd1498Szrj
112*38fd1498Szrj template <class _Tp1, class _Tp2>
113*38fd1498Szrj struct _SameTypeConcept
114*38fd1498Szrj {
115*38fd1498Szrj void __constraints() {
116*38fd1498Szrj typedef typename _Aux_require_same<_Tp1, _Tp2>::_Type _Required;
117*38fd1498Szrj }
118*38fd1498Szrj };
119*38fd1498Szrj
120*38fd1498Szrj template <class _Tp>
121*38fd1498Szrj struct _IntegerConcept {
122*38fd1498Szrj void __constraints() {
123*38fd1498Szrj __error_type_must_be_an_integer_type();
124*38fd1498Szrj }
125*38fd1498Szrj };
126*38fd1498Szrj template <> struct _IntegerConcept<short> { void __constraints() {} };
127*38fd1498Szrj template <> struct _IntegerConcept<unsigned short> { void __constraints(){} };
128*38fd1498Szrj template <> struct _IntegerConcept<int> { void __constraints() {} };
129*38fd1498Szrj template <> struct _IntegerConcept<unsigned int> { void __constraints() {} };
130*38fd1498Szrj template <> struct _IntegerConcept<long> { void __constraints() {} };
131*38fd1498Szrj template <> struct _IntegerConcept<unsigned long> { void __constraints() {} };
132*38fd1498Szrj template <> struct _IntegerConcept<long long> { void __constraints() {} };
133*38fd1498Szrj template <> struct _IntegerConcept<unsigned long long>
134*38fd1498Szrj { void __constraints() {} };
135*38fd1498Szrj
136*38fd1498Szrj template <class _Tp>
137*38fd1498Szrj struct _SignedIntegerConcept {
138*38fd1498Szrj void __constraints() {
139*38fd1498Szrj __error_type_must_be_a_signed_integer_type();
140*38fd1498Szrj }
141*38fd1498Szrj };
142*38fd1498Szrj template <> struct _SignedIntegerConcept<short> { void __constraints() {} };
143*38fd1498Szrj template <> struct _SignedIntegerConcept<int> { void __constraints() {} };
144*38fd1498Szrj template <> struct _SignedIntegerConcept<long> { void __constraints() {} };
145*38fd1498Szrj template <> struct _SignedIntegerConcept<long long> { void __constraints(){}};
146*38fd1498Szrj
147*38fd1498Szrj template <class _Tp>
148*38fd1498Szrj struct _UnsignedIntegerConcept {
149*38fd1498Szrj void __constraints() {
150*38fd1498Szrj __error_type_must_be_an_unsigned_integer_type();
151*38fd1498Szrj }
152*38fd1498Szrj };
153*38fd1498Szrj template <> struct _UnsignedIntegerConcept<unsigned short>
154*38fd1498Szrj { void __constraints() {} };
155*38fd1498Szrj template <> struct _UnsignedIntegerConcept<unsigned int>
156*38fd1498Szrj { void __constraints() {} };
157*38fd1498Szrj template <> struct _UnsignedIntegerConcept<unsigned long>
158*38fd1498Szrj { void __constraints() {} };
159*38fd1498Szrj template <> struct _UnsignedIntegerConcept<unsigned long long>
160*38fd1498Szrj { void __constraints() {} };
161*38fd1498Szrj
162*38fd1498Szrj //===========================================================================
163*38fd1498Szrj // Basic Concepts
164*38fd1498Szrj
165*38fd1498Szrj template <class _Tp>
166*38fd1498Szrj struct _DefaultConstructibleConcept
167*38fd1498Szrj {
168*38fd1498Szrj void __constraints() {
169*38fd1498Szrj _Tp __a _IsUnused; // require default constructor
170*38fd1498Szrj }
171*38fd1498Szrj };
172*38fd1498Szrj
173*38fd1498Szrj template <class _Tp>
174*38fd1498Szrj struct _AssignableConcept
175*38fd1498Szrj {
176*38fd1498Szrj void __constraints() {
177*38fd1498Szrj __a = __a; // require assignment operator
178*38fd1498Szrj __const_constraints(__a);
179*38fd1498Szrj }
180*38fd1498Szrj void __const_constraints(const _Tp& __b) {
181*38fd1498Szrj __a = __b; // const required for argument to assignment
182*38fd1498Szrj }
183*38fd1498Szrj _Tp __a;
184*38fd1498Szrj // possibly should be "Tp* a;" and then dereference "a" in constraint
185*38fd1498Szrj // functions? present way would require a default ctor, i think...
186*38fd1498Szrj };
187*38fd1498Szrj
188*38fd1498Szrj template <class _Tp>
189*38fd1498Szrj struct _CopyConstructibleConcept
190*38fd1498Szrj {
191*38fd1498Szrj void __constraints() {
192*38fd1498Szrj _Tp __a(__b); // require copy constructor
193*38fd1498Szrj _Tp* __ptr _IsUnused = &__a; // require address of operator
194*38fd1498Szrj __const_constraints(__a);
195*38fd1498Szrj }
196*38fd1498Szrj void __const_constraints(const _Tp& __a) {
197*38fd1498Szrj _Tp __c _IsUnused(__a); // require const copy constructor
198*38fd1498Szrj const _Tp* __ptr _IsUnused = &__a; // require const address of operator
199*38fd1498Szrj }
200*38fd1498Szrj _Tp __b;
201*38fd1498Szrj };
202*38fd1498Szrj
203*38fd1498Szrj // The SGI STL version of Assignable requires copy constructor and operator=
204*38fd1498Szrj template <class _Tp>
205*38fd1498Szrj struct _SGIAssignableConcept
206*38fd1498Szrj {
207*38fd1498Szrj void __constraints() {
208*38fd1498Szrj _Tp __b _IsUnused(__a);
209*38fd1498Szrj __a = __a; // require assignment operator
210*38fd1498Szrj __const_constraints(__a);
211*38fd1498Szrj }
212*38fd1498Szrj void __const_constraints(const _Tp& __b) {
213*38fd1498Szrj _Tp __c _IsUnused(__b);
214*38fd1498Szrj __a = __b; // const required for argument to assignment
215*38fd1498Szrj }
216*38fd1498Szrj _Tp __a;
217*38fd1498Szrj };
218*38fd1498Szrj
219*38fd1498Szrj template <class _From, class _To>
220*38fd1498Szrj struct _ConvertibleConcept
221*38fd1498Szrj {
222*38fd1498Szrj void __constraints() {
223*38fd1498Szrj _To __y _IsUnused = __x;
224*38fd1498Szrj }
225*38fd1498Szrj _From __x;
226*38fd1498Szrj };
227*38fd1498Szrj
228*38fd1498Szrj // The C++ standard requirements for many concepts talk about return
229*38fd1498Szrj // types that must be "convertible to bool". The problem with this
230*38fd1498Szrj // requirement is that it leaves the door open for evil proxies that
231*38fd1498Szrj // define things like operator|| with strange return types. Two
232*38fd1498Szrj // possible solutions are:
233*38fd1498Szrj // 1) require the return type to be exactly bool
234*38fd1498Szrj // 2) stay with convertible to bool, and also
235*38fd1498Szrj // specify stuff about all the logical operators.
236*38fd1498Szrj // For now we just test for convertible to bool.
237*38fd1498Szrj template <class _Tp>
238*38fd1498Szrj void __aux_require_boolean_expr(const _Tp& __t) {
239*38fd1498Szrj bool __x _IsUnused = __t;
240*38fd1498Szrj }
241*38fd1498Szrj
242*38fd1498Szrj // FIXME
243*38fd1498Szrj template <class _Tp>
244*38fd1498Szrj struct _EqualityComparableConcept
245*38fd1498Szrj {
246*38fd1498Szrj void __constraints() {
247*38fd1498Szrj __aux_require_boolean_expr(__a == __b);
248*38fd1498Szrj }
249*38fd1498Szrj _Tp __a, __b;
250*38fd1498Szrj };
251*38fd1498Szrj
252*38fd1498Szrj template <class _Tp>
253*38fd1498Szrj struct _LessThanComparableConcept
254*38fd1498Szrj {
255*38fd1498Szrj void __constraints() {
256*38fd1498Szrj __aux_require_boolean_expr(__a < __b);
257*38fd1498Szrj }
258*38fd1498Szrj _Tp __a, __b;
259*38fd1498Szrj };
260*38fd1498Szrj
261*38fd1498Szrj // This is equivalent to SGI STL's LessThanComparable.
262*38fd1498Szrj template <class _Tp>
263*38fd1498Szrj struct _ComparableConcept
264*38fd1498Szrj {
265*38fd1498Szrj void __constraints() {
266*38fd1498Szrj __aux_require_boolean_expr(__a < __b);
267*38fd1498Szrj __aux_require_boolean_expr(__a > __b);
268*38fd1498Szrj __aux_require_boolean_expr(__a <= __b);
269*38fd1498Szrj __aux_require_boolean_expr(__a >= __b);
270*38fd1498Szrj }
271*38fd1498Szrj _Tp __a, __b;
272*38fd1498Szrj };
273*38fd1498Szrj
274*38fd1498Szrj #define _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(_OP,_NAME) \
275*38fd1498Szrj template <class _First, class _Second> \
276*38fd1498Szrj struct _NAME { \
277*38fd1498Szrj void __constraints() { (void)__constraints_(); } \
278*38fd1498Szrj bool __constraints_() { \
279*38fd1498Szrj return __a _OP __b; \
280*38fd1498Szrj } \
281*38fd1498Szrj _First __a; \
282*38fd1498Szrj _Second __b; \
283*38fd1498Szrj }
284*38fd1498Szrj
285*38fd1498Szrj #define _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(_OP,_NAME) \
286*38fd1498Szrj template <class _Ret, class _First, class _Second> \
287*38fd1498Szrj struct _NAME { \
288*38fd1498Szrj void __constraints() { (void)__constraints_(); } \
289*38fd1498Szrj _Ret __constraints_() { \
290*38fd1498Szrj return __a _OP __b; \
291*38fd1498Szrj } \
292*38fd1498Szrj _First __a; \
293*38fd1498Szrj _Second __b; \
294*38fd1498Szrj }
295*38fd1498Szrj
296*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, _EqualOpConcept);
297*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(!=, _NotEqualOpConcept);
298*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<, _LessThanOpConcept);
299*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<=, _LessEqualOpConcept);
300*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>, _GreaterThanOpConcept);
301*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>=, _GreaterEqualOpConcept);
302*38fd1498Szrj
303*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(+, _PlusOpConcept);
304*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(*, _TimesOpConcept);
305*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(/, _DivideOpConcept);
306*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(-, _SubtractOpConcept);
307*38fd1498Szrj _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT(%, _ModOpConcept);
308*38fd1498Szrj
309*38fd1498Szrj #undef _GLIBCXX_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT
310*38fd1498Szrj #undef _GLIBCXX_DEFINE_BINARY_OPERATOR_CONSTRAINT
311*38fd1498Szrj
312*38fd1498Szrj //===========================================================================
313*38fd1498Szrj // Function Object Concepts
314*38fd1498Szrj
315*38fd1498Szrj template <class _Func, class _Return>
316*38fd1498Szrj struct _GeneratorConcept
317*38fd1498Szrj {
318*38fd1498Szrj void __constraints() {
319*38fd1498Szrj const _Return& __r _IsUnused = __f();// require operator() member function
320*38fd1498Szrj }
321*38fd1498Szrj _Func __f;
322*38fd1498Szrj };
323*38fd1498Szrj
324*38fd1498Szrj
325*38fd1498Szrj template <class _Func>
326*38fd1498Szrj struct _GeneratorConcept<_Func,void>
327*38fd1498Szrj {
328*38fd1498Szrj void __constraints() {
329*38fd1498Szrj __f(); // require operator() member function
330*38fd1498Szrj }
331*38fd1498Szrj _Func __f;
332*38fd1498Szrj };
333*38fd1498Szrj
334*38fd1498Szrj template <class _Func, class _Return, class _Arg>
335*38fd1498Szrj struct _UnaryFunctionConcept
336*38fd1498Szrj {
337*38fd1498Szrj void __constraints() {
338*38fd1498Szrj __r = __f(__arg); // require operator()
339*38fd1498Szrj }
340*38fd1498Szrj _Func __f;
341*38fd1498Szrj _Arg __arg;
342*38fd1498Szrj _Return __r;
343*38fd1498Szrj };
344*38fd1498Szrj
345*38fd1498Szrj template <class _Func, class _Arg>
346*38fd1498Szrj struct _UnaryFunctionConcept<_Func, void, _Arg> {
347*38fd1498Szrj void __constraints() {
348*38fd1498Szrj __f(__arg); // require operator()
349*38fd1498Szrj }
350*38fd1498Szrj _Func __f;
351*38fd1498Szrj _Arg __arg;
352*38fd1498Szrj };
353*38fd1498Szrj
354*38fd1498Szrj template <class _Func, class _Return, class _First, class _Second>
355*38fd1498Szrj struct _BinaryFunctionConcept
356*38fd1498Szrj {
357*38fd1498Szrj void __constraints() {
358*38fd1498Szrj __r = __f(__first, __second); // require operator()
359*38fd1498Szrj }
360*38fd1498Szrj _Func __f;
361*38fd1498Szrj _First __first;
362*38fd1498Szrj _Second __second;
363*38fd1498Szrj _Return __r;
364*38fd1498Szrj };
365*38fd1498Szrj
366*38fd1498Szrj template <class _Func, class _First, class _Second>
367*38fd1498Szrj struct _BinaryFunctionConcept<_Func, void, _First, _Second>
368*38fd1498Szrj {
369*38fd1498Szrj void __constraints() {
370*38fd1498Szrj __f(__first, __second); // require operator()
371*38fd1498Szrj }
372*38fd1498Szrj _Func __f;
373*38fd1498Szrj _First __first;
374*38fd1498Szrj _Second __second;
375*38fd1498Szrj };
376*38fd1498Szrj
377*38fd1498Szrj template <class _Func, class _Arg>
378*38fd1498Szrj struct _UnaryPredicateConcept
379*38fd1498Szrj {
380*38fd1498Szrj void __constraints() {
381*38fd1498Szrj __aux_require_boolean_expr(__f(__arg)); // require op() returning bool
382*38fd1498Szrj }
383*38fd1498Szrj _Func __f;
384*38fd1498Szrj _Arg __arg;
385*38fd1498Szrj };
386*38fd1498Szrj
387*38fd1498Szrj template <class _Func, class _First, class _Second>
388*38fd1498Szrj struct _BinaryPredicateConcept
389*38fd1498Szrj {
390*38fd1498Szrj void __constraints() {
391*38fd1498Szrj __aux_require_boolean_expr(__f(__a, __b)); // require op() returning bool
392*38fd1498Szrj }
393*38fd1498Szrj _Func __f;
394*38fd1498Szrj _First __a;
395*38fd1498Szrj _Second __b;
396*38fd1498Szrj };
397*38fd1498Szrj
398*38fd1498Szrj // use this when functor is used inside a container class like std::set
399*38fd1498Szrj template <class _Func, class _First, class _Second>
400*38fd1498Szrj struct _Const_BinaryPredicateConcept {
401*38fd1498Szrj void __constraints() {
402*38fd1498Szrj __const_constraints(__f);
403*38fd1498Szrj }
404*38fd1498Szrj void __const_constraints(const _Func& __fun) {
405*38fd1498Szrj __function_requires<_BinaryPredicateConcept<_Func, _First, _Second> >();
406*38fd1498Szrj // operator() must be a const member function
407*38fd1498Szrj __aux_require_boolean_expr(__fun(__a, __b));
408*38fd1498Szrj }
409*38fd1498Szrj _Func __f;
410*38fd1498Szrj _First __a;
411*38fd1498Szrj _Second __b;
412*38fd1498Szrj };
413*38fd1498Szrj
414*38fd1498Szrj //===========================================================================
415*38fd1498Szrj // Iterator Concepts
416*38fd1498Szrj
417*38fd1498Szrj template <class _Tp>
418*38fd1498Szrj struct _TrivialIteratorConcept
419*38fd1498Szrj {
420*38fd1498Szrj void __constraints() {
421*38fd1498Szrj // __function_requires< _DefaultConstructibleConcept<_Tp> >();
422*38fd1498Szrj __function_requires< _AssignableConcept<_Tp> >();
423*38fd1498Szrj __function_requires< _EqualityComparableConcept<_Tp> >();
424*38fd1498Szrj // typedef typename std::iterator_traits<_Tp>::value_type _V;
425*38fd1498Szrj (void)*__i; // require dereference operator
426*38fd1498Szrj }
427*38fd1498Szrj _Tp __i;
428*38fd1498Szrj };
429*38fd1498Szrj
430*38fd1498Szrj template <class _Tp>
431*38fd1498Szrj struct _Mutable_TrivialIteratorConcept
432*38fd1498Szrj {
433*38fd1498Szrj void __constraints() {
434*38fd1498Szrj __function_requires< _TrivialIteratorConcept<_Tp> >();
435*38fd1498Szrj *__i = *__j; // require dereference and assignment
436*38fd1498Szrj }
437*38fd1498Szrj _Tp __i, __j;
438*38fd1498Szrj };
439*38fd1498Szrj
440*38fd1498Szrj template <class _Tp>
441*38fd1498Szrj struct _InputIteratorConcept
442*38fd1498Szrj {
443*38fd1498Szrj void __constraints() {
444*38fd1498Szrj __function_requires< _TrivialIteratorConcept<_Tp> >();
445*38fd1498Szrj // require iterator_traits typedef's
446*38fd1498Szrj typedef typename std::iterator_traits<_Tp>::difference_type _Diff;
447*38fd1498Szrj // __function_requires< _SignedIntegerConcept<_Diff> >();
448*38fd1498Szrj typedef typename std::iterator_traits<_Tp>::reference _Ref;
449*38fd1498Szrj typedef typename std::iterator_traits<_Tp>::pointer _Pt;
450*38fd1498Szrj typedef typename std::iterator_traits<_Tp>::iterator_category _Cat;
451*38fd1498Szrj __function_requires< _ConvertibleConcept<
452*38fd1498Szrj typename std::iterator_traits<_Tp>::iterator_category,
453*38fd1498Szrj std::input_iterator_tag> >();
454*38fd1498Szrj ++__i; // require preincrement operator
455*38fd1498Szrj __i++; // require postincrement operator
456*38fd1498Szrj }
457*38fd1498Szrj _Tp __i;
458*38fd1498Szrj };
459*38fd1498Szrj
460*38fd1498Szrj template <class _Tp, class _ValueT>
461*38fd1498Szrj struct _OutputIteratorConcept
462*38fd1498Szrj {
463*38fd1498Szrj void __constraints() {
464*38fd1498Szrj __function_requires< _AssignableConcept<_Tp> >();
465*38fd1498Szrj ++__i; // require preincrement operator
466*38fd1498Szrj __i++; // require postincrement operator
467*38fd1498Szrj *__i++ = __t; // require postincrement and assignment
468*38fd1498Szrj }
469*38fd1498Szrj _Tp __i;
470*38fd1498Szrj _ValueT __t;
471*38fd1498Szrj };
472*38fd1498Szrj
473*38fd1498Szrj template <class _Tp>
474*38fd1498Szrj struct _ForwardIteratorConcept
475*38fd1498Szrj {
476*38fd1498Szrj void __constraints() {
477*38fd1498Szrj __function_requires< _InputIteratorConcept<_Tp> >();
478*38fd1498Szrj __function_requires< _DefaultConstructibleConcept<_Tp> >();
479*38fd1498Szrj __function_requires< _ConvertibleConcept<
480*38fd1498Szrj typename std::iterator_traits<_Tp>::iterator_category,
481*38fd1498Szrj std::forward_iterator_tag> >();
482*38fd1498Szrj typedef typename std::iterator_traits<_Tp>::reference _Ref;
483*38fd1498Szrj _Ref __r _IsUnused = *__i;
484*38fd1498Szrj }
485*38fd1498Szrj _Tp __i;
486*38fd1498Szrj };
487*38fd1498Szrj
488*38fd1498Szrj template <class _Tp>
489*38fd1498Szrj struct _Mutable_ForwardIteratorConcept
490*38fd1498Szrj {
491*38fd1498Szrj void __constraints() {
492*38fd1498Szrj __function_requires< _ForwardIteratorConcept<_Tp> >();
493*38fd1498Szrj *__i++ = *__i; // require postincrement and assignment
494*38fd1498Szrj }
495*38fd1498Szrj _Tp __i;
496*38fd1498Szrj };
497*38fd1498Szrj
498*38fd1498Szrj template <class _Tp>
499*38fd1498Szrj struct _BidirectionalIteratorConcept
500*38fd1498Szrj {
501*38fd1498Szrj void __constraints() {
502*38fd1498Szrj __function_requires< _ForwardIteratorConcept<_Tp> >();
503*38fd1498Szrj __function_requires< _ConvertibleConcept<
504*38fd1498Szrj typename std::iterator_traits<_Tp>::iterator_category,
505*38fd1498Szrj std::bidirectional_iterator_tag> >();
506*38fd1498Szrj --__i; // require predecrement operator
507*38fd1498Szrj __i--; // require postdecrement operator
508*38fd1498Szrj }
509*38fd1498Szrj _Tp __i;
510*38fd1498Szrj };
511*38fd1498Szrj
512*38fd1498Szrj template <class _Tp>
513*38fd1498Szrj struct _Mutable_BidirectionalIteratorConcept
514*38fd1498Szrj {
515*38fd1498Szrj void __constraints() {
516*38fd1498Szrj __function_requires< _BidirectionalIteratorConcept<_Tp> >();
517*38fd1498Szrj __function_requires< _Mutable_ForwardIteratorConcept<_Tp> >();
518*38fd1498Szrj *__i-- = *__i; // require postdecrement and assignment
519*38fd1498Szrj }
520*38fd1498Szrj _Tp __i;
521*38fd1498Szrj };
522*38fd1498Szrj
523*38fd1498Szrj
524*38fd1498Szrj template <class _Tp>
525*38fd1498Szrj struct _RandomAccessIteratorConcept
526*38fd1498Szrj {
527*38fd1498Szrj void __constraints() {
528*38fd1498Szrj __function_requires< _BidirectionalIteratorConcept<_Tp> >();
529*38fd1498Szrj __function_requires< _ComparableConcept<_Tp> >();
530*38fd1498Szrj __function_requires< _ConvertibleConcept<
531*38fd1498Szrj typename std::iterator_traits<_Tp>::iterator_category,
532*38fd1498Szrj std::random_access_iterator_tag> >();
533*38fd1498Szrj // ??? We don't use _Ref, are we just checking for "referenceability"?
534*38fd1498Szrj typedef typename std::iterator_traits<_Tp>::reference _Ref;
535*38fd1498Szrj
536*38fd1498Szrj __i += __n; // require assignment addition operator
537*38fd1498Szrj __i = __i + __n; __i = __n + __i; // require addition with difference type
538*38fd1498Szrj __i -= __n; // require assignment subtraction op
539*38fd1498Szrj __i = __i - __n; // require subtraction with
540*38fd1498Szrj // difference type
541*38fd1498Szrj __n = __i - __j; // require difference operator
542*38fd1498Szrj (void)__i[__n]; // require element access operator
543*38fd1498Szrj }
544*38fd1498Szrj _Tp __a, __b;
545*38fd1498Szrj _Tp __i, __j;
546*38fd1498Szrj typename std::iterator_traits<_Tp>::difference_type __n;
547*38fd1498Szrj };
548*38fd1498Szrj
549*38fd1498Szrj template <class _Tp>
550*38fd1498Szrj struct _Mutable_RandomAccessIteratorConcept
551*38fd1498Szrj {
552*38fd1498Szrj void __constraints() {
553*38fd1498Szrj __function_requires< _RandomAccessIteratorConcept<_Tp> >();
554*38fd1498Szrj __function_requires< _Mutable_BidirectionalIteratorConcept<_Tp> >();
555*38fd1498Szrj __i[__n] = *__i; // require element access and assignment
556*38fd1498Szrj }
557*38fd1498Szrj _Tp __i;
558*38fd1498Szrj typename std::iterator_traits<_Tp>::difference_type __n;
559*38fd1498Szrj };
560*38fd1498Szrj
561*38fd1498Szrj //===========================================================================
562*38fd1498Szrj // Container Concepts
563*38fd1498Szrj
564*38fd1498Szrj template <class _Container>
565*38fd1498Szrj struct _ContainerConcept
566*38fd1498Szrj {
567*38fd1498Szrj typedef typename _Container::value_type _Value_type;
568*38fd1498Szrj typedef typename _Container::difference_type _Difference_type;
569*38fd1498Szrj typedef typename _Container::size_type _Size_type;
570*38fd1498Szrj typedef typename _Container::const_reference _Const_reference;
571*38fd1498Szrj typedef typename _Container::const_pointer _Const_pointer;
572*38fd1498Szrj typedef typename _Container::const_iterator _Const_iterator;
573*38fd1498Szrj
574*38fd1498Szrj void __constraints() {
575*38fd1498Szrj __function_requires< _InputIteratorConcept<_Const_iterator> >();
576*38fd1498Szrj __function_requires< _AssignableConcept<_Container> >();
577*38fd1498Szrj const _Container __c;
578*38fd1498Szrj __i = __c.begin();
579*38fd1498Szrj __i = __c.end();
580*38fd1498Szrj __n = __c.size();
581*38fd1498Szrj __n = __c.max_size();
582*38fd1498Szrj __b = __c.empty();
583*38fd1498Szrj }
584*38fd1498Szrj bool __b;
585*38fd1498Szrj _Const_iterator __i;
586*38fd1498Szrj _Size_type __n;
587*38fd1498Szrj };
588*38fd1498Szrj
589*38fd1498Szrj template <class _Container>
590*38fd1498Szrj struct _Mutable_ContainerConcept
591*38fd1498Szrj {
592*38fd1498Szrj typedef typename _Container::value_type _Value_type;
593*38fd1498Szrj typedef typename _Container::reference _Reference;
594*38fd1498Szrj typedef typename _Container::iterator _Iterator;
595*38fd1498Szrj typedef typename _Container::pointer _Pointer;
596*38fd1498Szrj
597*38fd1498Szrj void __constraints() {
598*38fd1498Szrj __function_requires< _ContainerConcept<_Container> >();
599*38fd1498Szrj __function_requires< _AssignableConcept<_Value_type> >();
600*38fd1498Szrj __function_requires< _InputIteratorConcept<_Iterator> >();
601*38fd1498Szrj
602*38fd1498Szrj __i = __c.begin();
603*38fd1498Szrj __i = __c.end();
604*38fd1498Szrj __c.swap(__c2);
605*38fd1498Szrj }
606*38fd1498Szrj _Iterator __i;
607*38fd1498Szrj _Container __c, __c2;
608*38fd1498Szrj };
609*38fd1498Szrj
610*38fd1498Szrj template <class _ForwardContainer>
611*38fd1498Szrj struct _ForwardContainerConcept
612*38fd1498Szrj {
613*38fd1498Szrj void __constraints() {
614*38fd1498Szrj __function_requires< _ContainerConcept<_ForwardContainer> >();
615*38fd1498Szrj typedef typename _ForwardContainer::const_iterator _Const_iterator;
616*38fd1498Szrj __function_requires< _ForwardIteratorConcept<_Const_iterator> >();
617*38fd1498Szrj }
618*38fd1498Szrj };
619*38fd1498Szrj
620*38fd1498Szrj template <class _ForwardContainer>
621*38fd1498Szrj struct _Mutable_ForwardContainerConcept
622*38fd1498Szrj {
623*38fd1498Szrj void __constraints() {
624*38fd1498Szrj __function_requires< _ForwardContainerConcept<_ForwardContainer> >();
625*38fd1498Szrj __function_requires< _Mutable_ContainerConcept<_ForwardContainer> >();
626*38fd1498Szrj typedef typename _ForwardContainer::iterator _Iterator;
627*38fd1498Szrj __function_requires< _Mutable_ForwardIteratorConcept<_Iterator> >();
628*38fd1498Szrj }
629*38fd1498Szrj };
630*38fd1498Szrj
631*38fd1498Szrj template <class _ReversibleContainer>
632*38fd1498Szrj struct _ReversibleContainerConcept
633*38fd1498Szrj {
634*38fd1498Szrj typedef typename _ReversibleContainer::const_iterator _Const_iterator;
635*38fd1498Szrj typedef typename _ReversibleContainer::const_reverse_iterator
636*38fd1498Szrj _Const_reverse_iterator;
637*38fd1498Szrj
638*38fd1498Szrj void __constraints() {
639*38fd1498Szrj __function_requires< _ForwardContainerConcept<_ReversibleContainer> >();
640*38fd1498Szrj __function_requires< _BidirectionalIteratorConcept<_Const_iterator> >();
641*38fd1498Szrj __function_requires<
642*38fd1498Szrj _BidirectionalIteratorConcept<_Const_reverse_iterator> >();
643*38fd1498Szrj
644*38fd1498Szrj const _ReversibleContainer __c;
645*38fd1498Szrj _Const_reverse_iterator __i = __c.rbegin();
646*38fd1498Szrj __i = __c.rend();
647*38fd1498Szrj }
648*38fd1498Szrj };
649*38fd1498Szrj
650*38fd1498Szrj template <class _ReversibleContainer>
651*38fd1498Szrj struct _Mutable_ReversibleContainerConcept
652*38fd1498Szrj {
653*38fd1498Szrj typedef typename _ReversibleContainer::iterator _Iterator;
654*38fd1498Szrj typedef typename _ReversibleContainer::reverse_iterator _Reverse_iterator;
655*38fd1498Szrj
656*38fd1498Szrj void __constraints() {
657*38fd1498Szrj __function_requires<_ReversibleContainerConcept<_ReversibleContainer> >();
658*38fd1498Szrj __function_requires<
659*38fd1498Szrj _Mutable_ForwardContainerConcept<_ReversibleContainer> >();
660*38fd1498Szrj __function_requires<_Mutable_BidirectionalIteratorConcept<_Iterator> >();
661*38fd1498Szrj __function_requires<
662*38fd1498Szrj _Mutable_BidirectionalIteratorConcept<_Reverse_iterator> >();
663*38fd1498Szrj
664*38fd1498Szrj _Reverse_iterator __i = __c.rbegin();
665*38fd1498Szrj __i = __c.rend();
666*38fd1498Szrj }
667*38fd1498Szrj _ReversibleContainer __c;
668*38fd1498Szrj };
669*38fd1498Szrj
670*38fd1498Szrj template <class _RandomAccessContainer>
671*38fd1498Szrj struct _RandomAccessContainerConcept
672*38fd1498Szrj {
673*38fd1498Szrj typedef typename _RandomAccessContainer::size_type _Size_type;
674*38fd1498Szrj typedef typename _RandomAccessContainer::const_reference _Const_reference;
675*38fd1498Szrj typedef typename _RandomAccessContainer::const_iterator _Const_iterator;
676*38fd1498Szrj typedef typename _RandomAccessContainer::const_reverse_iterator
677*38fd1498Szrj _Const_reverse_iterator;
678*38fd1498Szrj
679*38fd1498Szrj void __constraints() {
680*38fd1498Szrj __function_requires<
681*38fd1498Szrj _ReversibleContainerConcept<_RandomAccessContainer> >();
682*38fd1498Szrj __function_requires< _RandomAccessIteratorConcept<_Const_iterator> >();
683*38fd1498Szrj __function_requires<
684*38fd1498Szrj _RandomAccessIteratorConcept<_Const_reverse_iterator> >();
685*38fd1498Szrj
686*38fd1498Szrj const _RandomAccessContainer __c;
687*38fd1498Szrj _Const_reference __r _IsUnused = __c[__n];
688*38fd1498Szrj }
689*38fd1498Szrj _Size_type __n;
690*38fd1498Szrj };
691*38fd1498Szrj
692*38fd1498Szrj template <class _RandomAccessContainer>
693*38fd1498Szrj struct _Mutable_RandomAccessContainerConcept
694*38fd1498Szrj {
695*38fd1498Szrj typedef typename _RandomAccessContainer::size_type _Size_type;
696*38fd1498Szrj typedef typename _RandomAccessContainer::reference _Reference;
697*38fd1498Szrj typedef typename _RandomAccessContainer::iterator _Iterator;
698*38fd1498Szrj typedef typename _RandomAccessContainer::reverse_iterator _Reverse_iterator;
699*38fd1498Szrj
700*38fd1498Szrj void __constraints() {
701*38fd1498Szrj __function_requires<
702*38fd1498Szrj _RandomAccessContainerConcept<_RandomAccessContainer> >();
703*38fd1498Szrj __function_requires<
704*38fd1498Szrj _Mutable_ReversibleContainerConcept<_RandomAccessContainer> >();
705*38fd1498Szrj __function_requires< _Mutable_RandomAccessIteratorConcept<_Iterator> >();
706*38fd1498Szrj __function_requires<
707*38fd1498Szrj _Mutable_RandomAccessIteratorConcept<_Reverse_iterator> >();
708*38fd1498Szrj
709*38fd1498Szrj _Reference __r _IsUnused = __c[__i];
710*38fd1498Szrj }
711*38fd1498Szrj _Size_type __i;
712*38fd1498Szrj _RandomAccessContainer __c;
713*38fd1498Szrj };
714*38fd1498Szrj
715*38fd1498Szrj // A Sequence is inherently mutable
716*38fd1498Szrj template <class _Sequence>
717*38fd1498Szrj struct _SequenceConcept
718*38fd1498Szrj {
719*38fd1498Szrj typedef typename _Sequence::reference _Reference;
720*38fd1498Szrj typedef typename _Sequence::const_reference _Const_reference;
721*38fd1498Szrj
722*38fd1498Szrj void __constraints() {
723*38fd1498Szrj // Matt Austern's book puts DefaultConstructible here, the C++
724*38fd1498Szrj // standard places it in Container
725*38fd1498Szrj // function_requires< DefaultConstructible<Sequence> >();
726*38fd1498Szrj __function_requires< _Mutable_ForwardContainerConcept<_Sequence> >();
727*38fd1498Szrj __function_requires< _DefaultConstructibleConcept<_Sequence> >();
728*38fd1498Szrj
729*38fd1498Szrj _Sequence
730*38fd1498Szrj __c _IsUnused(__n, __t),
731*38fd1498Szrj __c2 _IsUnused(__first, __last);
732*38fd1498Szrj
733*38fd1498Szrj __c.insert(__p, __t);
734*38fd1498Szrj __c.insert(__p, __n, __t);
735*38fd1498Szrj __c.insert(__p, __first, __last);
736*38fd1498Szrj
737*38fd1498Szrj __c.erase(__p);
738*38fd1498Szrj __c.erase(__p, __q);
739*38fd1498Szrj
740*38fd1498Szrj _Reference __r _IsUnused = __c.front();
741*38fd1498Szrj
742*38fd1498Szrj __const_constraints(__c);
743*38fd1498Szrj }
744*38fd1498Szrj void __const_constraints(const _Sequence& __c) {
745*38fd1498Szrj _Const_reference __r _IsUnused = __c.front();
746*38fd1498Szrj }
747*38fd1498Szrj typename _Sequence::value_type __t;
748*38fd1498Szrj typename _Sequence::size_type __n;
749*38fd1498Szrj typename _Sequence::value_type *__first, *__last;
750*38fd1498Szrj typename _Sequence::iterator __p, __q;
751*38fd1498Szrj };
752*38fd1498Szrj
753*38fd1498Szrj template <class _FrontInsertionSequence>
754*38fd1498Szrj struct _FrontInsertionSequenceConcept
755*38fd1498Szrj {
756*38fd1498Szrj void __constraints() {
757*38fd1498Szrj __function_requires< _SequenceConcept<_FrontInsertionSequence> >();
758*38fd1498Szrj
759*38fd1498Szrj __c.push_front(__t);
760*38fd1498Szrj __c.pop_front();
761*38fd1498Szrj }
762*38fd1498Szrj _FrontInsertionSequence __c;
763*38fd1498Szrj typename _FrontInsertionSequence::value_type __t;
764*38fd1498Szrj };
765*38fd1498Szrj
766*38fd1498Szrj template <class _BackInsertionSequence>
767*38fd1498Szrj struct _BackInsertionSequenceConcept
768*38fd1498Szrj {
769*38fd1498Szrj typedef typename _BackInsertionSequence::reference _Reference;
770*38fd1498Szrj typedef typename _BackInsertionSequence::const_reference _Const_reference;
771*38fd1498Szrj
772*38fd1498Szrj void __constraints() {
773*38fd1498Szrj __function_requires< _SequenceConcept<_BackInsertionSequence> >();
774*38fd1498Szrj
775*38fd1498Szrj __c.push_back(__t);
776*38fd1498Szrj __c.pop_back();
777*38fd1498Szrj _Reference __r _IsUnused = __c.back();
778*38fd1498Szrj }
779*38fd1498Szrj void __const_constraints(const _BackInsertionSequence& __c) {
780*38fd1498Szrj _Const_reference __r _IsUnused = __c.back();
781*38fd1498Szrj };
782*38fd1498Szrj _BackInsertionSequence __c;
783*38fd1498Szrj typename _BackInsertionSequence::value_type __t;
784*38fd1498Szrj };
785*38fd1498Szrj
786*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
787*38fd1498Szrj } // namespace
788*38fd1498Szrj
789*38fd1498Szrj #pragma GCC diagnostic pop
790*38fd1498Szrj #undef _IsUnused
791*38fd1498Szrj
792*38fd1498Szrj #endif // _GLIBCXX_BOOST_CONCEPT_CHECK
793*38fd1498Szrj
794*38fd1498Szrj
795