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