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