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