boost_concept_check.h

Go to the documentation of this file.
00001 // Copyright (C) 2004 Free Software Foundation, Inc.
00002 //
00003 // This file is part of the GNU ISO C++ Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the
00005 // terms of the GNU General Public License as published by the
00006 // Free Software Foundation; either version 2, or (at your option)
00007 // any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 
00014 // You should have received a copy of the GNU General Public License along
00015 // with this library; see the file COPYING.  If not, write to the Free
00016 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00017 // USA.
00018 
00019 // As a special exception, you may use this file as part of a free software
00020 // library without restriction.  Specifically, if other files instantiate
00021 // templates or use macros or inline functions from this file, or you compile
00022 // this file and link it with other files to produce an executable, this
00023 // file does not by itself cause the resulting executable to be covered by
00024 // the GNU General Public License.  This exception does not however
00025 // invalidate any other reasons why the executable file might be covered by
00026 // the GNU General Public License.
00027 
00028 // (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
00029 // sell and distribute this software is granted provided this
00030 // copyright notice appears in all copies. This software is provided
00031 // "as is" without express or implied warranty, and with no claim as
00032 // to its suitability for any purpose.
00033 //
00034 
00035 // GCC Note:  based on version 1.12.0 of the Boost library.
00036 
00037 /** @file boost_concept_check.h
00038  *  This is an internal header file, included by other library headers.
00039  *  You should not attempt to use it directly.
00040  */
00041 
00042 #ifndef _GLIBCPP_BOOST_CONCEPT_CHECK
00043 #define _GLIBCPP_BOOST_CONCEPT_CHECK 1
00044 
00045 #pragma GCC system_header
00046 #include <cstddef>                // for ptrdiff_t, used next
00047 #include <bits/stl_iterator_base_types.h>    // for traits and tags
00048 #include <utility>                           // for pair<>
00049 
00050 
00051 namespace __gnu_cxx
00052 {
00053 
00054 #define _IsUnused __attribute__ ((__unused__))
00055 
00056 // When the C-C code is in use, we would like this function to do as little
00057 // as possible at runtime, use as few resources as possible, and hopefully
00058 // be elided out of existence... hmmm.
00059 template <class _Concept>
00060 inline void __function_requires()
00061 {
00062   void (_Concept::*__x)() _IsUnused = &_Concept::__constraints;
00063 }
00064 
00065 
00066 // ??? Should the "concept_checking*" structs begin with more than _ ?
00067 #define _GLIBCPP_CLASS_REQUIRES(_type_var, _ns, _concept) \
00068   typedef void (_ns::_concept <_type_var>::* _func##_type_var##_concept)(); \
00069   template <_func##_type_var##_concept _Tp1> \
00070   struct _concept_checking##_type_var##_concept { }; \
00071   typedef _concept_checking##_type_var##_concept< \
00072     &_ns::_concept <_type_var>::__constraints> \
00073     _concept_checking_typedef##_type_var##_concept
00074 
00075 #define _GLIBCPP_CLASS_REQUIRES2(_type_var1, _type_var2, _ns, _concept) \
00076   typedef void (_ns::_concept <_type_var1,_type_var2>::* _func##_type_var1##_type_var2##_concept)(); \
00077   template <_func##_type_var1##_type_var2##_concept _Tp1> \
00078   struct _concept_checking##_type_var1##_type_var2##_concept { }; \
00079   typedef _concept_checking##_type_var1##_type_var2##_concept< \
00080     &_ns::_concept <_type_var1,_type_var2>::__constraints> \
00081     _concept_checking_typedef##_type_var1##_type_var2##_concept
00082 
00083 #define _GLIBCPP_CLASS_REQUIRES3(_type_var1, _type_var2, _type_var3, _ns, _concept) \
00084   typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3>::* _func##_type_var1##_type_var2##_type_var3##_concept)(); \
00085   template <_func##_type_var1##_type_var2##_type_var3##_concept _Tp1> \
00086   struct _concept_checking##_type_var1##_type_var2##_type_var3##_concept { }; \
00087   typedef _concept_checking##_type_var1##_type_var2##_type_var3##_concept< \
00088     &_ns::_concept <_type_var1,_type_var2,_type_var3>::__constraints>  \
00089   _concept_checking_typedef##_type_var1##_type_var2##_type_var3##_concept
00090 
00091 #define _GLIBCPP_CLASS_REQUIRES4(_type_var1, _type_var2, _type_var3, _type_var4, _ns, _concept) \
00092   typedef void (_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::* _func##_type_var1##_type_var2##_type_var3##_type_var4##_concept)(); \
00093   template <_func##_type_var1##_type_var2##_type_var3##_type_var4##_concept _Tp1> \
00094   struct _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept { }; \
00095   typedef _concept_checking##_type_var1##_type_var2##_type_var3##_type_var4##_concept< \
00096   &_ns::_concept <_type_var1,_type_var2,_type_var3,_type_var4>::__constraints> \
00097     _concept_checking_typedef##_type_var1##_type_var2##_type_var3##_type_var4##_concept
00098 
00099 
00100 template <class _Tp1, class _Tp2>
00101 struct _Aux_require_same { };
00102 
00103 template <class _Tp>
00104 struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; };
00105 
00106   template <class _Tp1, class _Tp2>
00107   struct _SameTypeConcept
00108   {
00109     void __constraints() {
00110       typedef typename _Aux_require_same<_Tp1, _Tp2>::_Type _Required;
00111     }
00112   };
00113 
00114   template <class _Tp>
00115   struct _IntegerConcept {
00116     void __constraints() { 
00117       __error_type_must_be_an_integer_type();
00118     }
00119   };
00120   template <> struct _IntegerConcept<short> { void __constraints() {} };
00121   template <> struct _IntegerConcept<unsigned short> { void __constraints(){} };
00122   template <> struct _IntegerConcept<int> { void __constraints() {} };
00123   template <> struct _IntegerConcept<unsigned int> { void __constraints() {} };
00124   template <> struct _IntegerConcept<long> { void __constraints() {} };
00125   template <> struct _IntegerConcept<unsigned long> { void __constraints() {} };
00126   template <> struct _IntegerConcept<long long> { void __constraints() {} };
00127   template <> struct _IntegerConcept<unsigned long long>
00128                                                 { void __constraints() {} };
00129 
00130   template <class _Tp>
00131   struct _SignedIntegerConcept {
00132     void __constraints() { 
00133       __error_type_must_be_a_signed_integer_type();
00134     }
00135   };
00136   template <> struct _SignedIntegerConcept<short> { void __constraints() {} };
00137   template <> struct _SignedIntegerConcept<int> { void __constraints() {} };
00138   template <> struct _SignedIntegerConcept<long> { void __constraints() {} };
00139   template <> struct _SignedIntegerConcept<long long> { void __constraints(){}};
00140 
00141   template <class _Tp>
00142   struct _UnsignedIntegerConcept {
00143     void __constraints() { 
00144       __error_type_must_be_an_unsigned_integer_type();
00145     }
00146   };
00147   template <> struct _UnsignedIntegerConcept<unsigned short>
00148     { void __constraints() {} };
00149   template <> struct _UnsignedIntegerConcept<unsigned int>
00150     { void __constraints() {} };
00151   template <> struct _UnsignedIntegerConcept<unsigned long>
00152     { void __constraints() {} };
00153   template <> struct _UnsignedIntegerConcept<unsigned long long>
00154     { void __constraints() {} };
00155 
00156   //===========================================================================
00157   // Basic Concepts
00158 
00159   template <class _Tp>
00160   struct _DefaultConstructibleConcept
00161   {
00162     void __constraints() {
00163       _Tp __a _IsUnused;                // require default constructor
00164     }
00165   };
00166 
00167   template <class _Tp>
00168   struct _AssignableConcept
00169   {
00170     void __constraints() {
00171       __a = __a;                        // require assignment operator
00172       __const_constraints(__a);
00173     }
00174     void __const_constraints(const _Tp& __b) {
00175       __a = __b;                   // const required for argument to assignment
00176     }
00177     _Tp __a;
00178     // possibly should be "Tp* a;" and then dereference "a" in constraint
00179     // functions?  present way would require a default ctor, i think...
00180   };
00181 
00182   template <class _Tp>
00183   struct _CopyConstructibleConcept
00184   {
00185     void __constraints() {
00186       _Tp __a(__b);                     // require copy constructor
00187       _Tp* __ptr _IsUnused = &__a;      // require address of operator
00188       __const_constraints(__a);
00189     }
00190     void __const_constraints(const _Tp& __a) {
00191       _Tp __c(__a) _IsUnused;           // require const copy constructor
00192       const _Tp* __ptr _IsUnused = &__a; // require const address of operator
00193     }
00194     _Tp __b;
00195   };
00196 
00197   // The SGI STL version of Assignable requires copy constructor and operator=
00198   template <class _Tp>
00199   struct _SGIAssignableConcept
00200   {
00201     void __constraints() {
00202       _Tp __b(__a) _IsUnused;
00203       __a = __a;                        // require assignment operator
00204       __const_constraints(__a);
00205     }
00206     void __const_constraints(const _Tp& __b) {
00207       _Tp __c(__b) _IsUnused;
00208       __a = __b;              // const required for argument to assignment
00209     }
00210     _Tp __a;
00211   };
00212 
00213   template <class _From, class _To>
00214   struct _ConvertibleConcept
00215   {
00216     void __constraints() {
00217       _To __y _IsUnused = __x;
00218     }
00219     _From __x;
00220   };
00221 
00222   // The C++ standard requirements for many concepts talk about return
00223   // types that must be "convertible to bool".  The problem with this
00224   // requirement is that it leaves the door open for evil proxies that
00225   // define things like operator|| with strange return types.  Two
00226   // possible solutions are:
00227   // 1) require the return type to be exactly bool
00228   // 2) stay with convertible to bool, and also
00229   //    specify stuff about all the logical operators.
00230   // For now we just test for convertible to bool.
00231   template <class _Tp>
00232   void __aux_require_boolean_expr(const _Tp& __t) {
00233     bool __x _IsUnused = __t;
00234   }
00235 
00236 // FIXME
00237   template <class _Tp>
00238   struct _EqualityComparableConcept
00239   {
00240     void __constraints() {
00241       __aux_require_boolean_expr(__a == __b);
00242       __aux_require_boolean_expr(__a != __b);
00243     }
00244     _Tp __a, __b;
00245   };
00246 
00247   template <class _Tp>
00248   struct _LessThanComparableConcept
00249   {
00250     void __constraints() {
00251       __aux_require_boolean_expr(__a < __b);
00252     }
00253     _Tp __a, __b;
00254   };
00255 
00256   // This is equivalent to SGI STL's LessThanComparable.
00257   template <class _Tp>
00258   struct _ComparableConcept
00259   {
00260     void __constraints() {
00261       __aux_require_boolean_expr(__a < __b);
00262       __aux_require_boolean_expr(__a > __b);
00263       __aux_require_boolean_expr(__a <= __b);
00264       __aux_require_boolean_expr(__a >= __b);
00265     }
00266     _Tp __a, __b;
00267   };
00268 
00269 #define _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(_OP,_NAME) \
00270   template <class _First, class _Second> \
00271   struct _NAME { \
00272     void __constraints() { (void)__constraints_(); } \
00273     bool __constraints_() {  \
00274       return  __a _OP __b; \
00275     } \
00276     _First __a; \
00277     _Second __b; \
00278   }
00279 
00280 #define _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(_OP,_NAME) \
00281   template <class _Ret, class _First, class _Second> \
00282   struct _NAME { \
00283     void __constraints() { (void)__constraints_(); } \
00284     _Ret __constraints_() {  \
00285       return __a _OP __b; \
00286     } \
00287     _First __a; \
00288     _Second __b; \
00289   }
00290 
00291   _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, _EqualOpConcept);
00292   _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(!=, _NotEqualOpConcept);
00293   _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<, _LessThanOpConcept);
00294   _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<=, _LessEqualOpConcept);
00295   _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>, _GreaterThanOpConcept);
00296   _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>=, _GreaterEqualOpConcept);
00297 
00298   _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(+, _PlusOpConcept);
00299   _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(*, _TimesOpConcept);
00300   _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(/, _DivideOpConcept);
00301   _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(-, _SubtractOpConcept);
00302   _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT(%, _ModOpConcept);
00303 
00304 #undef _GLIBCPP_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT
00305 #undef _GLIBCPP_DEFINE_BINARY_OPERATOR_CONSTRAINT
00306 
00307   //===========================================================================
00308   // Function Object Concepts
00309 
00310   template <class _Func, class _Return>
00311   struct _GeneratorConcept
00312   {
00313     void __constraints() {
00314       const _Return& __r _IsUnused = __f();// require operator() member function
00315     }
00316     _Func __f;
00317   };
00318 
00319 
00320   template <class _Func>
00321   struct _GeneratorConcept<_Func,void>
00322   {
00323     void __constraints() {
00324       __f();                            // require operator() member function
00325     }
00326     _Func __f;
00327   };
00328 
00329   template <class _Func, class _Return, class _Arg>
00330   struct _UnaryFunctionConcept
00331   {
00332     void __constraints() {
00333       __r = __f(__arg);                  // require operator()
00334     }
00335     _Func __f;
00336     _Arg __arg;
00337     _Return __r;
00338   };
00339 
00340   template <class _Func, class _Arg>
00341   struct _UnaryFunctionConcept<_Func, void, _Arg> {
00342     void __constraints() { 
00343       __f(__arg);                       // require operator()
00344     }
00345     _Func __f;
00346     _Arg __arg;
00347   };
00348 
00349   template <class _Func, class _Return, class _First, class _Second>
00350   struct _BinaryFunctionConcept
00351   {
00352     void __constraints() { 
00353       __r = __f(__first, __second);     // require operator()
00354     }
00355     _Func __f;
00356     _First __first;
00357     _Second __second;
00358     _Return __r;
00359   };
00360 
00361   template <class _Func, class _First, class _Second>
00362   struct _BinaryFunctionConcept<_Func, void, _First, _Second>
00363   {
00364     void __constraints() {
00365       __f(__first, __second);           // require operator()
00366     }
00367     _Func __f;
00368     _First __first;
00369     _Second __second;
00370   };
00371 
00372   template <class _Func, class _Arg>
00373   struct _UnaryPredicateConcept
00374   {
00375     void __constraints() {
00376       __aux_require_boolean_expr(__f(__arg)); // require op() returning bool
00377     }
00378     _Func __f;
00379     _Arg __arg;
00380   };
00381 
00382   template <class _Func, class _First, class _Second>
00383   struct _BinaryPredicateConcept
00384   {
00385     void __constraints() {
00386       __aux_require_boolean_expr(__f(__a, __b)); // require op() returning bool
00387     }
00388     _Func __f;
00389     _First __a;
00390     _Second __b;
00391   };
00392 
00393   // use this when functor is used inside a container class like std::set
00394   template <class _Func, class _First, class _Second>
00395   struct _Const_BinaryPredicateConcept {
00396     void __constraints() { 
00397       __const_constraints(__f);
00398     }
00399     void __const_constraints(const _Func& __fun) {
00400       __function_requires<_BinaryPredicateConcept<_Func, _First, _Second> >();
00401       // operator() must be a const member function
00402       __aux_require_boolean_expr(__fun(__a, __b));
00403     }
00404     _Func __f;
00405     _First __a;
00406     _Second __b;
00407   };
00408 
00409   //===========================================================================
00410   // Iterator Concepts
00411 
00412   template <class _Tp>
00413   struct _TrivialIteratorConcept
00414   {
00415     void __constraints() {
00416 //    __function_requires< _DefaultConstructibleConcept<_Tp> >();
00417       __function_requires< _AssignableConcept<_Tp> >();
00418       __function_requires< _EqualityComparableConcept<_Tp> >();
00419 //      typedef typename std::iterator_traits<_Tp>::value_type _V;
00420       (void)*__i;                       // require dereference operator
00421     }
00422     _Tp __i;
00423   };
00424 
00425   template <class _Tp>
00426   struct _Mutable_TrivialIteratorConcept
00427   {
00428     void __constraints() {
00429       __function_requires< _TrivialIteratorConcept<_Tp> >();
00430       *__i = *__j;                      // require dereference and assignment
00431     }
00432     _Tp __i, __j;
00433   };
00434 
00435   template <class _Tp>
00436   struct _InputIteratorConcept
00437   {
00438     void __constraints() {
00439       __function_requires< _TrivialIteratorConcept<_Tp> >();
00440       // require iterator_traits typedef's
00441       typedef typename std::iterator_traits<_Tp>::difference_type _D;
00442 //      __function_requires< _SignedIntegerConcept<_D> >();
00443       typedef typename std::iterator_traits<_Tp>::reference _R;
00444       typedef typename std::iterator_traits<_Tp>::pointer _Pt;
00445       typedef typename std::iterator_traits<_Tp>::iterator_category _Cat;
00446       __function_requires< _ConvertibleConcept<
00447         typename std::iterator_traits<_Tp>::iterator_category,
00448         std::input_iterator_tag> >();
00449       ++__i;                            // require preincrement operator
00450       __i++;                            // require postincrement operator
00451     }
00452     _Tp __i;
00453   };
00454 
00455   template <class _Tp, class _ValueT>
00456   struct _OutputIteratorConcept
00457   {
00458     void __constraints() {
00459       __function_requires< _AssignableConcept<_Tp> >();
00460       ++__i;                            // require preincrement operator
00461       __i++;                            // require postincrement operator
00462       *__i++ = __t;                     // require postincrement and assignment
00463     }
00464     _Tp __i;
00465     _ValueT __t;
00466   };
00467 
00468   template <class _Tp>
00469   struct _ForwardIteratorConcept
00470   {
00471     void __constraints() {
00472       __function_requires< _InputIteratorConcept<_Tp> >();
00473       __function_requires< _DefaultConstructibleConcept<_Tp> >();
00474       __function_requires< _ConvertibleConcept<
00475         typename std::iterator_traits<_Tp>::iterator_category,
00476         std::forward_iterator_tag> >();
00477       typedef typename std::iterator_traits<_Tp>::reference _R;
00478       _R __r _IsUnused = *__i;
00479     }
00480     _Tp __i;
00481   };
00482 
00483   template <class _Tp>
00484   struct _Mutable_ForwardIteratorConcept
00485   {
00486     void __constraints() {
00487       __function_requires< _ForwardIteratorConcept<_Tp> >();
00488       *__i++ = *__i;                    // require postincrement and assignment
00489     }
00490     _Tp __i;
00491   };
00492 
00493   template <class _Tp>
00494   struct _BidirectionalIteratorConcept
00495   {
00496     void __constraints() {
00497       __function_requires< _ForwardIteratorConcept<_Tp> >();
00498       __function_requires< _ConvertibleConcept<
00499         typename std::iterator_traits<_Tp>::iterator_category,
00500         std::bidirectional_iterator_tag> >();
00501       --__i;                            // require predecrement operator
00502       __i--;                            // require postdecrement operator
00503     }
00504     _Tp __i;
00505   };
00506 
00507   template <class _Tp>
00508   struct _Mutable_BidirectionalIteratorConcept
00509   {
00510     void __constraints() {
00511       __function_requires< _BidirectionalIteratorConcept<_Tp> >();
00512       __function_requires< _Mutable_ForwardIteratorConcept<_Tp> >();
00513       *__i-- = *__i;                    // require postdecrement and assignment
00514     }
00515     _Tp __i;
00516   };
00517 
00518 
00519   template <class _Tp>
00520   struct _RandomAccessIteratorConcept
00521   {
00522     void __constraints() {
00523       __function_requires< _BidirectionalIteratorConcept<_Tp> >();
00524       __function_requires< _ComparableConcept<_Tp> >();
00525       __function_requires< _ConvertibleConcept<
00526         typename std::iterator_traits<_Tp>::iterator_category,
00527         std::random_access_iterator_tag> >();
00528       // ??? We don't use _R, are we just checking for "referenceability"?
00529       typedef typename std::iterator_traits<_Tp>::reference _R;
00530 
00531       __i += __n;                       // require assignment addition operator
00532       __i = __i + __n; __i = __n + __i; // require addition with difference type
00533       __i -= __n;                       // require assignment subtraction op
00534       __i = __i - __n;                  // require subtraction with
00535                                         //            difference type
00536       __n = __i - __j;                  // require difference operator
00537       (void)__i[__n];                   // require element access operator
00538     }
00539     _Tp __a, __b;
00540     _Tp __i, __j;
00541     typename std::iterator_traits<_Tp>::difference_type __n;
00542   };
00543 
00544   template <class _Tp>
00545   struct _Mutable_RandomAccessIteratorConcept
00546   {
00547     void __constraints() {
00548       __function_requires< _RandomAccessIteratorConcept<_Tp> >();
00549       __function_requires< _Mutable_BidirectionalIteratorConcept<_Tp> >();
00550       __i[__n] = *__i;                  // require element access and assignment
00551     }
00552     _Tp __i;
00553     typename std::iterator_traits<_Tp>::difference_type __n;
00554   };
00555 
00556   //===========================================================================
00557   // Container Concepts
00558 
00559   template <class _Container>
00560   struct _ContainerConcept
00561   {
00562     typedef typename _Container::value_type _Value_type;
00563     typedef typename _Container::difference_type _Difference_type;
00564     typedef typename _Container::size_type _Size_type;
00565     typedef typename _Container::const_reference _Const_reference;
00566     typedef typename _Container::const_pointer _Const_pointer;
00567     typedef typename _Container::const_iterator _Const_iterator;
00568 
00569     void __constraints() {
00570       __function_requires< _InputIteratorConcept<_Const_iterator> >();
00571       __function_requires< _AssignableConcept<_Container> >();
00572       const _Container __c;
00573       __i = __c.begin();
00574       __i = __c.end();
00575       __n = __c.size();
00576       __n = __c.max_size();
00577       __b = __c.empty();
00578     }
00579     bool __b;
00580     _Const_iterator __i;
00581     _Size_type __n;
00582   };
00583 
00584   template <class _Container>
00585   struct _Mutable_ContainerConcept
00586   {
00587     typedef typename _Container::value_type _Value_type;
00588     typedef typename _Container::reference _Reference;
00589     typedef typename _Container::iterator _Iterator;
00590     typedef typename _Container::pointer _Pointer;
00591     
00592     void __constraints() {
00593       __function_requires< _ContainerConcept<_Container> >();
00594       __function_requires< _AssignableConcept<_Value_type> >();
00595       __function_requires< _InputIteratorConcept<_Iterator> >();
00596 
00597       __i = __c.begin();
00598       __i = __c.end();
00599       __c.swap(__c2);
00600     }
00601     _Iterator __i;
00602     _Container __c, __c2;
00603   };
00604 
00605   template <class _ForwardContainer>
00606   struct _ForwardContainerConcept
00607   {
00608     void __constraints() {
00609       __function_requires< _ContainerConcept<_ForwardContainer> >();
00610       typedef typename _ForwardContainer::const_iterator _Const_iterator;
00611       __function_requires< _ForwardIteratorConcept<_Const_iterator> >();
00612     }
00613   };  
00614 
00615   template <class _ForwardContainer>
00616   struct _Mutable_ForwardContainerConcept
00617   {
00618     void __constraints() {
00619       __function_requires< _ForwardContainerConcept<_ForwardContainer> >();
00620       __function_requires< _Mutable_ContainerConcept<_ForwardContainer> >();
00621       typedef typename _ForwardContainer::iterator _Iterator;
00622       __function_requires< _Mutable_ForwardIteratorConcept<_Iterator> >();
00623     }
00624   };  
00625 
00626   template <class _ReversibleContainer>
00627   struct _ReversibleContainerConcept
00628   {
00629     typedef typename _ReversibleContainer::const_iterator _Const_iterator;
00630     typedef typename _ReversibleContainer::const_reverse_iterator
00631       _Const_reverse_iterator;
00632 
00633     void __constraints() {
00634       __function_requires< _ForwardContainerConcept<_ReversibleContainer> >();
00635       __function_requires< _BidirectionalIteratorConcept<_Const_iterator> >();
00636       __function_requires<
00637         _BidirectionalIteratorConcept<_Const_reverse_iterator> >();
00638 
00639       const _ReversibleContainer __c;
00640       _Const_reverse_iterator __i = __c.rbegin();
00641       __i = __c.rend();
00642     }
00643   };
00644 
00645   template <class _ReversibleContainer>
00646   struct _Mutable_ReversibleContainerConcept
00647   {
00648     typedef typename _ReversibleContainer::iterator _Iterator;
00649     typedef typename _ReversibleContainer::reverse_iterator _Reverse_iterator;
00650 
00651     void __constraints() {
00652       __function_requires<_ReversibleContainerConcept<_ReversibleContainer> >();
00653       __function_requires<
00654         _Mutable_ForwardContainerConcept<_ReversibleContainer> >();
00655       __function_requires<_Mutable_BidirectionalIteratorConcept<_Iterator> >();
00656       __function_requires<
00657         _Mutable_BidirectionalIteratorConcept<_Reverse_iterator> >();
00658 
00659       _Reverse_iterator __i = __c.rbegin();
00660       __i = __c.rend();
00661     }
00662     _ReversibleContainer __c;
00663   };
00664 
00665   template <class _RandomAccessContainer>
00666   struct _RandomAccessContainerConcept
00667   {
00668     typedef typename _RandomAccessContainer::size_type _Size_type;
00669     typedef typename _RandomAccessContainer::const_reference _Const_reference;
00670     typedef typename _RandomAccessContainer::const_iterator _Const_iterator;
00671     typedef typename _RandomAccessContainer::const_reverse_iterator
00672       _Const_reverse_iterator;
00673 
00674     void __constraints() {
00675       __function_requires<
00676         _ReversibleContainerConcept<_RandomAccessContainer> >();
00677       __function_requires< _RandomAccessIteratorConcept<_Const_iterator> >();
00678       __function_requires<
00679         _RandomAccessIteratorConcept<_Const_reverse_iterator> >();
00680 
00681       const _RandomAccessContainer __c;
00682       _Const_reference __r _IsUnused = __c[__n];
00683     }
00684     _Size_type __n;
00685   };
00686 
00687   template <class _RandomAccessContainer>
00688   struct _Mutable_RandomAccessContainerConcept
00689   {
00690     typedef typename _RandomAccessContainer::size_type _Size_type;
00691     typedef typename _RandomAccessContainer::reference _Reference;
00692     typedef typename _RandomAccessContainer::iterator _Iterator;
00693     typedef typename _RandomAccessContainer::reverse_iterator _Reverse_iterator;
00694 
00695     void __constraints() {
00696       __function_requires<
00697         _RandomAccessContainerConcept<_RandomAccessContainer> >();
00698       __function_requires<
00699         _Mutable_ReversibleContainerConcept<_RandomAccessContainer> >();
00700       __function_requires< _Mutable_RandomAccessIteratorConcept<_Iterator> >();
00701       __function_requires<
00702         _Mutable_RandomAccessIteratorConcept<_Reverse_iterator> >();
00703 
00704       _Reference __r _IsUnused = __c[__i];
00705     }
00706     _Size_type __i;
00707     _RandomAccessContainer __c;
00708   };
00709 
00710   // A Sequence is inherently mutable
00711   template <class _Sequence>
00712   struct _SequenceConcept
00713   {
00714     typedef typename _Sequence::reference _Reference;
00715     typedef typename _Sequence::const_reference _Const_reference;
00716 
00717     void __constraints() {
00718       // Matt Austern's book puts DefaultConstructible here, the C++
00719       // standard places it in Container
00720       //    function_requires< DefaultConstructible<Sequence> >();
00721       __function_requires< _Mutable_ForwardContainerConcept<_Sequence> >();
00722       __function_requires< _DefaultConstructibleConcept<_Sequence> >();
00723 
00724       _Sequence 
00725         __c(__n, __t) _IsUnused,
00726         __c2(__first, __last) _IsUnused;
00727 
00728       __c.insert(__p, __t);
00729       __c.insert(__p, __n, __t);
00730       __c.insert(__p, __first, __last);
00731 
00732       __c.erase(__p);
00733       __c.erase(__p, __q);
00734 
00735       _Reference __r _IsUnused = __c.front();
00736 
00737       __const_constraints(__c);
00738     }
00739     void __const_constraints(const _Sequence& __c) {
00740       _Const_reference __r _IsUnused = __c.front();
00741     }
00742     typename _Sequence::value_type __t;
00743     typename _Sequence::size_type __n;
00744     typename _Sequence::value_type *__first, *__last;
00745     typename _Sequence::iterator __p, __q;
00746   };
00747 
00748   template <class _FrontInsertionSequence>
00749   struct _FrontInsertionSequenceConcept
00750   {
00751     void __constraints() {
00752       __function_requires< _SequenceConcept<_FrontInsertionSequence> >();
00753 
00754       __c.push_front(__t);
00755       __c.pop_front();
00756     }
00757     _FrontInsertionSequence __c;
00758     typename _FrontInsertionSequence::value_type __t;
00759   };
00760 
00761   template <class _BackInsertionSequence>
00762   struct _BackInsertionSequenceConcept
00763   {
00764     typedef typename _BackInsertionSequence::reference _Reference;
00765     typedef typename _BackInsertionSequence::const_reference _Const_reference;
00766 
00767     void __constraints() {
00768       __function_requires< _SequenceConcept<_BackInsertionSequence> >();
00769 
00770       __c.push_back(__t);
00771       __c.pop_back();
00772       _Reference __r _IsUnused = __c.back();
00773     }
00774     void __const_constraints(const _BackInsertionSequence& __c) {
00775       _Const_reference __r _IsUnused = __c.back();
00776     };
00777     _BackInsertionSequence __c;
00778     typename _BackInsertionSequence::value_type __t;
00779   };
00780 
00781   template <class _AssociativeContainer>
00782   struct _AssociativeContainerConcept
00783   {
00784     void __constraints() {
00785       __function_requires< _ForwardContainerConcept<_AssociativeContainer> >();
00786       __function_requires<
00787         _DefaultConstructibleConcept<_AssociativeContainer> >();
00788     
00789       __i = __c.find(__k);
00790       __r = __c.equal_range(__k);
00791       __c.erase(__k);
00792       __c.erase(__i);
00793       __c.erase(__r.first, __r.second);
00794       __const_constraints(__c);
00795     }
00796     void __const_constraints(const _AssociativeContainer& __c) {
00797       __ci = __c.find(__k);
00798       __n = __c.count(__k);
00799       __cr = __c.equal_range(__k);
00800     }
00801     typedef typename _AssociativeContainer::iterator _Iterator;
00802     typedef typename _AssociativeContainer::const_iterator _Const_iterator;
00803 
00804     _AssociativeContainer __c;
00805     _Iterator __i;
00806     std::pair<_Iterator,_Iterator> __r;
00807     _Const_iterator __ci;
00808     std::pair<_Const_iterator,_Const_iterator> __cr;
00809     typename _AssociativeContainer::key_type __k;
00810     typename _AssociativeContainer::size_type __n;
00811   };
00812 
00813   template <class _UniqueAssociativeContainer>
00814   struct _UniqueAssociativeContainerConcept
00815   {
00816     void __constraints() {
00817       __function_requires<
00818         _AssociativeContainerConcept<_UniqueAssociativeContainer> >();
00819     
00820       _UniqueAssociativeContainer __c(__first, __last);
00821       
00822       __pos_flag = __c.insert(__t);
00823       __c.insert(__first, __last);
00824     }
00825     std::pair<typename _UniqueAssociativeContainer::iterator, bool> __pos_flag;
00826     typename _UniqueAssociativeContainer::value_type __t;
00827     typename _UniqueAssociativeContainer::value_type *__first, *__last;
00828   };
00829 
00830   template <class _MultipleAssociativeContainer>
00831   struct _MultipleAssociativeContainerConcept
00832   {
00833     void __constraints() {
00834       __function_requires<
00835         _AssociativeContainerConcept<_MultipleAssociativeContainer> >();
00836 
00837       _MultipleAssociativeContainer __c(__first, __last);
00838       
00839       __pos = __c.insert(__t);
00840       __c.insert(__first, __last);
00841 
00842     }
00843     typename _MultipleAssociativeContainer::iterator __pos _IsUnused;
00844     typename _MultipleAssociativeContainer::value_type __t;
00845     typename _MultipleAssociativeContainer::value_type *__first, *__last;
00846   };
00847 
00848   template <class _SimpleAssociativeContainer>
00849   struct _SimpleAssociativeContainerConcept
00850   {
00851     void __constraints() {
00852       __function_requires<
00853         _AssociativeContainerConcept<_SimpleAssociativeContainer> >();
00854       typedef typename _SimpleAssociativeContainer::key_type _Key_type;
00855       typedef typename _SimpleAssociativeContainer::value_type _Value_type;
00856       typedef typename _Aux_require_same<_Key_type, _Value_type>::_Type
00857         _Requqired;
00858     }
00859   };
00860 
00861   template <class _SimpleAssociativeContainer>
00862   struct _PairAssociativeContainerConcept
00863   {
00864     void __constraints() {
00865       __function_requires<
00866         _AssociativeContainerConcept<_SimpleAssociativeContainer> >();
00867       typedef typename _SimpleAssociativeContainer::key_type _Key_type;
00868       typedef typename _SimpleAssociativeContainer::value_type _Value_type;
00869       typedef typename _SimpleAssociativeContainer::mapped_type _Mapped_type;
00870       typedef std::pair<const _Key_type, _Mapped_type> _Required_value_type;
00871       typedef typename _Aux_require_same<_Value_type,
00872         _Required_value_type>::_Type _Required;
00873     }
00874   };
00875 
00876   template <class _SortedAssociativeContainer>
00877   struct _SortedAssociativeContainerConcept
00878   {
00879     void __constraints() {
00880       __function_requires<
00881         _AssociativeContainerConcept<_SortedAssociativeContainer> >();
00882       __function_requires<
00883         _ReversibleContainerConcept<_SortedAssociativeContainer> >();
00884 
00885       _SortedAssociativeContainer 
00886         __c(__kc) _IsUnused,
00887         __c2(__first, __last) _IsUnused,
00888         __c3(__first, __last, __kc) _IsUnused;
00889 
00890       __p = __c.upper_bound(__k);
00891       __p = __c.lower_bound(__k);
00892       __r = __c.equal_range(__k);
00893       
00894       __c.insert(__p, __t);
00895     }
00896     void __const_constraints(const _SortedAssociativeContainer& __c) {
00897       __kc = __c.key_comp();
00898       __vc = __c.value_comp();
00899 
00900       __cp = __c.upper_bound(__k);
00901       __cp = __c.lower_bound(__k);
00902       __cr = __c.equal_range(__k);
00903     }
00904     typename _SortedAssociativeContainer::key_compare __kc;
00905     typename _SortedAssociativeContainer::value_compare __vc;
00906     typename _SortedAssociativeContainer::value_type __t;
00907     typename _SortedAssociativeContainer::key_type __k;
00908     typedef typename _SortedAssociativeContainer::iterator _Iterator;
00909     typedef typename _SortedAssociativeContainer::const_iterator
00910       _Const_iterator;
00911 
00912     _Iterator __p;
00913     _Const_iterator __cp;
00914     std::pair<_Iterator,_Iterator> __r;
00915     std::pair<_Const_iterator,_Const_iterator> __cr;
00916     typename _SortedAssociativeContainer::value_type *__first, *__last;
00917   };
00918 
00919   // HashedAssociativeContainer
00920 
00921 } // namespace __gnu_cxx
00922 
00923 #undef _IsUnused
00924 
00925 #endif // _GLIBCPP_BOOST_CONCEPT_CHECK
00926 
00927 

Generated on Sat Mar 19 19:39:54 2005 for libstdc++-v3 Source by  doxygen 1.4.1