boost_concept_check.h 27 KB

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