concept_checks.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute and sell this software
  6. * and its documentation for any purpose is hereby granted without fee,
  7. * provided that the above copyright notice appear in all copies and
  8. * that both that copyright notice and this permission notice appear
  9. * in supporting documentation. Silicon Graphics makes no
  10. * representations about the suitability of this software for any
  11. * purpose. It is provided "as is" without express or implied warranty.
  12. */
  13. #ifndef __CONCEPT_CHECKS_H
  14. #define __CONCEPT_CHECKS_H
  15. /*
  16. Use these macro like assertions, but they assert properties
  17. on types (usually template arguments). In technical terms they
  18. verify whether a type "models" a "concept".
  19. This set of requirements and the terminology used here is derived
  20. from the book "Generic Programming and the STL" by Matt Austern
  21. (Addison Wesley). For further information please consult that
  22. book. The requirements also are intended to match the ANSI/ISO C++
  23. standard.
  24. This file covers the basic concepts and the iterator concepts.
  25. There are several other files that provide the requirements
  26. for the STL containers:
  27. container_concepts.h
  28. sequence_concepts.h
  29. assoc_container_concepts.h
  30. Jeremy Siek, 1999
  31. TO DO:
  32. - some issues with regards to concept classification and mutability
  33. including AssociativeContianer -> ForwardContainer
  34. and SortedAssociativeContainer -> ReversibleContainer
  35. - HashedAssociativeContainer
  36. - Allocator
  37. - Function Object Concepts
  38. */
  39. #ifndef _STLP_USE_CONCEPT_CHECKS
  40. // Some compilers lack the features that are necessary for concept checks.
  41. // On those compilers we define the concept check macros to do nothing.
  42. #define _STLP_REQUIRES(__type_var, __concept) do {} while(0)
  43. #define _STLP_CLASS_REQUIRES(__type_var, __concept) \
  44. static int __##__type_var##_##__concept
  45. #define _STLP_CONVERTIBLE(__type_x, __type_y) do {} while(0)
  46. #define _STLP_REQUIRES_SAME_TYPE(__type_x, __type_y) do {} while(0)
  47. #define _STLP_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y) \
  48. static int __##__type_x##__type_y##_require_same_type
  49. #define _STLP_GENERATOR_CHECK(__func, __ret) do {} while(0)
  50. #define _STLP_CLASS_GENERATOR_CHECK(__func, __ret) \
  51. static int __##__func##__ret##_generator_check
  52. #define _STLP_UNARY_FUNCTION_CHECK(__func, __ret, __arg) do {} while(0)
  53. #define _STLP_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
  54. static int __##__func##__ret##__arg##_unary_function_check
  55. #define _STLP_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
  56. do {} while(0)
  57. #define _STLP_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
  58. static int __##__func##__ret##__first##__second##_binary_function_check
  59. #define _STLP_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
  60. do {} while(0)
  61. #define _STLP_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
  62. static int __##__opname##__ret##__first##__second##_require_binary_op
  63. #else /* _STLP_USE_CONCEPT_CHECKS */
  64. // This macro tests whether the template argument "__type_var"
  65. // satisfies the requirements of "__concept". Here is a list of concepts
  66. // that we know how to check:
  67. // _Allocator
  68. // _Assignable
  69. // _DefaultConstructible
  70. // _EqualityComparable
  71. // _LessThanComparable
  72. // _TrivialIterator
  73. // _InputIterator
  74. // _OutputIterator
  75. // _ForwardIterator
  76. // _BidirectionalIterator
  77. // _RandomAccessIterator
  78. // _Mutable_TrivialIterator
  79. // _Mutable_ForwardIterator
  80. // _Mutable_BidirectionalIterator
  81. // _Mutable_RandomAccessIterator
  82. #define _STLP_REQUIRES(__type_var, __concept) \
  83. do { \
  84. void (*__x)( __type_var ) = __concept##_concept_specification< __type_var >\
  85. ::##__concept##_requirement_violation; __x = __x; } while (0)
  86. // Use this to check whether type X is convertible to type Y
  87. #define _STLP_CONVERTIBLE(__type_x, __type_y) \
  88. do { \
  89. void (*__x)( __type_x , __type_y ) = _STL_CONVERT_ERROR< __type_x , \
  90. __type_y >::__type_X_is_not_convertible_to_type_Y; \
  91. __x = __x; } while (0)
  92. // Use this to test whether two template arguments are the same type
  93. #define _STLP_REQUIRES_SAME_TYPE(__type_x, __type_y) \
  94. do { \
  95. void (*__x)( __type_x , __type_y ) = _STL_SAME_TYPE_ERROR< __type_x, \
  96. __type_y >::__type_X_not_same_as_type_Y; \
  97. __x = __x; } while (0)
  98. // function object checks
  99. #define _STLP_GENERATOR_CHECK(__func, __ret) \
  100. do { \
  101. __ret (*__x)( __func&) = \
  102. _STL_GENERATOR_ERROR< \
  103. __func, __ret>::__generator_requirement_violation; \
  104. __x = __x; } while (0)
  105. #define _STLP_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
  106. do { \
  107. __ret (*__x)( __func&, const __arg& ) = \
  108. _STL_UNARY_FUNCTION_ERROR< \
  109. __func, __ret, __arg>::__unary_function_requirement_violation; \
  110. __x = __x; } while (0)
  111. #define _STLP_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
  112. do { \
  113. __ret (*__x)( __func&, const __first&, const __second& ) = \
  114. _STL_BINARY_FUNCTION_ERROR< \
  115. __func, __ret, __first, __second>::__binary_function_requirement_violation; \
  116. __x = __x; } while (0)
  117. #define _STLP_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
  118. do { \
  119. __ret (*__x)( __first&, __second& ) = _STL_BINARY##__opname##_ERROR< \
  120. __ret, __first, __second>::__binary_operator_requirement_violation; \
  121. __ret (*__y)( const __first&, const __second& ) = \
  122. _STL_BINARY##__opname##_ERROR< __ret, __first, __second>:: \
  123. __const_binary_operator_requirement_violation; \
  124. __y = __y; __x = __x; } while (0)
  125. #ifdef _STLP_NO_FUNCTION_PTR_IN_CLASS_TEMPLATE
  126. #define _STLP_CLASS_REQUIRES(__type_var, __concept)
  127. #define _STLP_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y)
  128. #define _STLP_CLASS_GENERATOR_CHECK(__func, __ret)
  129. #define _STLP_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg)
  130. #define _STLP_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second)
  131. #define _STLP_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second)
  132. #else
  133. // Use this macro inside of template classes, where you would
  134. // like to place requirements on the template arguments to the class
  135. // Warning: do not pass pointers and such (e.g. T*) in as the __type_var,
  136. // since the type_var is used to construct identifiers. Instead typedef
  137. // the pointer type, then use the typedef name for the __type_var.
  138. #define _STLP_CLASS_REQUIRES(__type_var, __concept) \
  139. typedef void (* __func##__type_var##__concept)( __type_var ); \
  140. template <__func##__type_var##__concept _Tp1> \
  141. struct __dummy_struct_##__type_var##__concept { }; \
  142. static __dummy_struct_##__type_var##__concept< \
  143. __concept##_concept_specification< \
  144. __type_var>::__concept##_requirement_violation> \
  145. __dummy_ptr_##__type_var##__concept
  146. #define _STLP_CLASS_REQUIRES_SAME_TYPE(__type_x, __type_y) \
  147. typedef void (* __func_##__type_x##__type_y##same_type)( __type_x, \
  148. __type_y ); \
  149. template < __func_##__type_x##__type_y##same_type _Tp1> \
  150. struct __dummy_struct_##__type_x##__type_y##_same_type { }; \
  151. static __dummy_struct_##__type_x##__type_y##_same_type< \
  152. _STL_SAME_TYPE_ERROR<__type_x, __type_y>::__type_X_not_same_as_type_Y> \
  153. __dummy_ptr_##__type_x##__type_y##_same_type
  154. #define _STLP_CLASS_GENERATOR_CHECK(__func, __ret) \
  155. typedef __ret (* __f_##__func##__ret##_generator)( __func& ); \
  156. template <__f_##__func##__ret##_generator _Tp1> \
  157. struct __dummy_struct_##__func##__ret##_generator { }; \
  158. static __dummy_struct_##__func##__ret##_generator< \
  159. _STL_GENERATOR_ERROR< \
  160. __func, __ret>::__generator_requirement_violation> \
  161. __dummy_ptr_##__func##__ret##_generator
  162. #define _STLP_CLASS_UNARY_FUNCTION_CHECK(__func, __ret, __arg) \
  163. typedef __ret (* __f_##__func##__ret##__arg##_unary_check)( __func&, \
  164. const __arg& ); \
  165. template <__f_##__func##__ret##__arg##_unary_check _Tp1> \
  166. struct __dummy_struct_##__func##__ret##__arg##_unary_check { }; \
  167. static __dummy_struct_##__func##__ret##__arg##_unary_check< \
  168. _STL_UNARY_FUNCTION_ERROR< \
  169. __func, __ret, __arg>::__unary_function_requirement_violation> \
  170. __dummy_ptr_##__func##__ret##__arg##_unary_check
  171. #define _STLP_CLASS_BINARY_FUNCTION_CHECK(__func, __ret, __first, __second) \
  172. typedef __ret (* __f_##__func##__ret##__first##__second##_binary_check)( __func&, const __first&,\
  173. const __second& ); \
  174. template <__f_##__func##__ret##__first##__second##_binary_check _Tp1> \
  175. struct __dummy_struct_##__func##__ret##__first##__second##_binary_check { }; \
  176. static __dummy_struct_##__func##__ret##__first##__second##_binary_check< \
  177. _STL_BINARY_FUNCTION_ERROR<__func, __ret, __first, __second>:: \
  178. __binary_function_requirement_violation> \
  179. __dummy_ptr_##__func##__ret##__first##__second##_binary_check
  180. #define _STLP_CLASS_REQUIRES_BINARY_OP(__opname, __ret, __first, __second) \
  181. typedef __ret (* __f_##__func##__ret##__first##__second##_binary_op)(const __first&, \
  182. const __second& ); \
  183. template <__f_##__func##__ret##__first##__second##_binary_op _Tp1> \
  184. struct __dummy_struct_##__func##__ret##__first##__second##_binary_op { }; \
  185. static __dummy_struct_##__func##__ret##__first##__second##_binary_op< \
  186. _STL_BINARY##__opname##_ERROR<__ret, __first, __second>:: \
  187. __binary_operator_requirement_violation> \
  188. __dummy_ptr_##__func##__ret##__first##__second##_binary_op
  189. #endif
  190. /* helper class for finding non-const version of a type. Need to have
  191. something to assign to etc. when testing constant iterators. */
  192. template <class _Tp>
  193. struct _Mutable_trait {
  194. typedef _Tp _Type;
  195. };
  196. template <class _Tp>
  197. struct _Mutable_trait<const _Tp> {
  198. typedef _Tp _Type;
  199. };
  200. /* helper function for avoiding compiler warnings about unused variables */
  201. template <class _Type>
  202. void __sink_unused_warning(_Type) { }
  203. template <class _TypeX, class _TypeY>
  204. struct _STL_CONVERT_ERROR {
  205. static void
  206. __type_X_is_not_convertible_to_type_Y(_TypeX __x, _TypeY) {
  207. _TypeY __y = __x;
  208. __sink_unused_warning(__y);
  209. }
  210. };
  211. template <class _Type> struct __check_equal { };
  212. template <class _TypeX, class _TypeY>
  213. struct _STL_SAME_TYPE_ERROR {
  214. static void
  215. __type_X_not_same_as_type_Y(_TypeX , _TypeY ) {
  216. __check_equal<_TypeX> t1 = __check_equal<_TypeY>();
  217. }
  218. };
  219. // Some Functon Object Checks
  220. template <class _Func, class _Ret>
  221. struct _STL_GENERATOR_ERROR {
  222. static _Ret __generator_requirement_violation(_Func& __f) {
  223. return __f();
  224. }
  225. };
  226. template <class _Func>
  227. struct _STL_GENERATOR_ERROR<_Func, void> {
  228. static void __generator_requirement_violation(_Func& __f) {
  229. __f();
  230. }
  231. };
  232. template <class _Func, class _Ret, class _Arg>
  233. struct _STL_UNARY_FUNCTION_ERROR {
  234. static _Ret
  235. __unary_function_requirement_violation(_Func& __f,
  236. const _Arg& __arg) {
  237. return __f(__arg);
  238. }
  239. };
  240. template <class _Func, class _Arg>
  241. struct _STL_UNARY_FUNCTION_ERROR<_Func, void, _Arg> {
  242. static void
  243. __unary_function_requirement_violation(_Func& __f,
  244. const _Arg& __arg) {
  245. __f(__arg);
  246. }
  247. };
  248. template <class _Func, class _Ret, class _First, class _Second>
  249. struct _STL_BINARY_FUNCTION_ERROR {
  250. static _Ret
  251. __binary_function_requirement_violation(_Func& __f,
  252. const _First& __first,
  253. const _Second& __second) {
  254. return __f(__first, __second);
  255. }
  256. };
  257. template <class _Func, class _First, class _Second>
  258. struct _STL_BINARY_FUNCTION_ERROR<_Func, void, _First, _Second> {
  259. static void
  260. __binary_function_requirement_violation(_Func& __f,
  261. const _First& __first,
  262. const _Second& __second) {
  263. __f(__first, __second);
  264. }
  265. };
  266. #define _STLP_DEFINE_BINARY_OP_CHECK(_OP, _NAME) \
  267. template <class _Ret, class _First, class _Second> \
  268. struct _STL_BINARY##_NAME##_ERROR { \
  269. static _Ret \
  270. __const_binary_operator_requirement_violation(const _First& __first, \
  271. const _Second& __second) { \
  272. return __first _OP __second; \
  273. } \
  274. static _Ret \
  275. __binary_operator_requirement_violation(_First& __first, \
  276. _Second& __second) { \
  277. return __first _OP __second; \
  278. } \
  279. }
  280. _STLP_DEFINE_BINARY_OP_CHECK(==, _OP_EQUAL);
  281. _STLP_DEFINE_BINARY_OP_CHECK(!=, _OP_NOT_EQUAL);
  282. _STLP_DEFINE_BINARY_OP_CHECK(<, _OP_LESS_THAN);
  283. _STLP_DEFINE_BINARY_OP_CHECK(<=, _OP_LESS_EQUAL);
  284. _STLP_DEFINE_BINARY_OP_CHECK(>, _OP_GREATER_THAN);
  285. _STLP_DEFINE_BINARY_OP_CHECK(>=, _OP_GREATER_EQUAL);
  286. _STLP_DEFINE_BINARY_OP_CHECK(+, _OP_PLUS);
  287. _STLP_DEFINE_BINARY_OP_CHECK(*, _OP_TIMES);
  288. _STLP_DEFINE_BINARY_OP_CHECK(/, _OP_DIVIDE);
  289. _STLP_DEFINE_BINARY_OP_CHECK(-, _OP_SUBTRACT);
  290. _STLP_DEFINE_BINARY_OP_CHECK(%, _OP_MOD);
  291. // ...
  292. // TODO, add unary operators (prefix and postfix)
  293. /*
  294. The presence of this class is just to trick EDG into displaying
  295. these error messages before any other errors. Without the
  296. classes, the errors in the functions get reported after
  297. other class errors deep inside the library. The name
  298. choice just makes for an eye catching error message :)
  299. */
  300. struct _STL_ERROR {
  301. template <class _Type>
  302. static _Type
  303. __default_constructor_requirement_violation(_Type) {
  304. return _Type();
  305. }
  306. template <class _Type>
  307. static _Type
  308. __assignment_operator_requirement_violation(_Type __a) {
  309. __a = __a;
  310. return __a;
  311. }
  312. template <class _Type>
  313. static _Type
  314. __copy_constructor_requirement_violation(_Type __a) {
  315. _Type __c(__a);
  316. return __c;
  317. }
  318. template <class _Type>
  319. static _Type
  320. __const_parameter_required_for_copy_constructor(_Type /* __a */,
  321. const _Type& __b) {
  322. _Type __c(__b);
  323. return __c;
  324. }
  325. template <class _Type>
  326. static _Type
  327. __const_parameter_required_for_assignment_operator(_Type __a,
  328. const _Type& __b) {
  329. __a = __b;
  330. return __a;
  331. }
  332. template <class _Type>
  333. static _Type
  334. __less_than_comparable_requirement_violation(_Type __a, _Type __b) {
  335. if (__a < __b || __a > __b || __a <= __b || __a >= __b) return __a;
  336. return __b;
  337. }
  338. template <class _Type>
  339. static _Type
  340. __equality_comparable_requirement_violation(_Type __a, _Type __b) {
  341. if (__a == __b || __a != __b) return __a;
  342. return __b;
  343. }
  344. template <class _Iterator>
  345. static void
  346. __dereference_operator_requirement_violation(_Iterator __i) {
  347. __sink_unused_warning(*__i);
  348. }
  349. template <class _Iterator>
  350. static void
  351. __dereference_operator_and_assignment_requirement_violation(_Iterator __i) {
  352. *__i = *__i;
  353. }
  354. template <class _Iterator>
  355. static void
  356. __preincrement_operator_requirement_violation(_Iterator __i) {
  357. ++__i;
  358. }
  359. template <class _Iterator>
  360. static void
  361. __postincrement_operator_requirement_violation(_Iterator __i) {
  362. __i++;
  363. }
  364. template <class _Iterator>
  365. static void
  366. __predecrement_operator_requirement_violation(_Iterator __i) {
  367. --__i;
  368. }
  369. template <class _Iterator>
  370. static void
  371. __postdecrement_operator_requirement_violation(_Iterator __i) {
  372. __i--;
  373. }
  374. template <class _Iterator, class _Type>
  375. static void
  376. __postincrement_operator_and_assignment_requirement_violation(_Iterator __i,
  377. _Type __t) {
  378. *__i++ = __t;
  379. }
  380. template <class _Iterator, class _Distance>
  381. static _Iterator
  382. __iterator_addition_assignment_requirement_violation(_Iterator __i,
  383. _Distance __n) {
  384. __i += __n;
  385. return __i;
  386. }
  387. template <class _Iterator, class _Distance>
  388. static _Iterator
  389. __iterator_addition_requirement_violation(_Iterator __i, _Distance __n) {
  390. __i = __i + __n;
  391. __i = __n + __i;
  392. return __i;
  393. }
  394. template <class _Iterator, class _Distance>
  395. static _Iterator
  396. __iterator_subtraction_assignment_requirement_violation(_Iterator __i,
  397. _Distance __n) {
  398. __i -= __n;
  399. return __i;
  400. }
  401. template <class _Iterator, class _Distance>
  402. static _Iterator
  403. __iterator_subtraction_requirement_violation(_Iterator __i, _Distance __n) {
  404. __i = __i - __n;
  405. return __i;
  406. }
  407. template <class _Iterator, class _Distance>
  408. static _Distance
  409. __difference_operator_requirement_violation(_Iterator __i, _Iterator __j,
  410. _Distance __n) {
  411. __n = __i - __j;
  412. return __n;
  413. }
  414. template <class _Exp, class _Type, class _Distance>
  415. static _Type
  416. __element_access_operator_requirement_violation(_Exp __x, _Type*,
  417. _Distance __n) {
  418. return __x[__n];
  419. }
  420. template <class _Exp, class _Type, class _Distance>
  421. static void
  422. __element_assignment_operator_requirement_violation(_Exp __x,
  423. _Type* __t,
  424. _Distance __n) {
  425. __x[__n] = *__t;
  426. }
  427. }; /* _STL_ERROR */
  428. /* Associated Type Requirements */
  429. _STLP_BEGIN_NAMESPACE
  430. template <class _Iterator> struct iterator_traits;
  431. _STLP_END_NAMESPACE
  432. template <class _Iter>
  433. struct __value_type_type_definition_requirement_violation {
  434. typedef typename __STD::iterator_traits<_Iter>::value_type value_type;
  435. };
  436. template <class _Iter>
  437. struct __difference_type_type_definition_requirement_violation {
  438. typedef typename __STD::iterator_traits<_Iter>::difference_type
  439. difference_type;
  440. };
  441. template <class _Iter>
  442. struct __reference_type_definition_requirement_violation {
  443. typedef typename __STD::iterator_traits<_Iter>::reference reference;
  444. };
  445. template <class _Iter>
  446. struct __pointer_type_definition_requirement_violation {
  447. typedef typename __STD::iterator_traits<_Iter>::pointer pointer;
  448. };
  449. template <class _Iter>
  450. struct __iterator_category_type_definition_requirement_violation {
  451. typedef typename __STD::iterator_traits<_Iter>::iterator_category
  452. iterator_category;
  453. };
  454. /* Assignable Requirements */
  455. template <class _Type>
  456. struct _Assignable_concept_specification {
  457. static void _Assignable_requirement_violation(_Type __a) {
  458. _STL_ERROR::__assignment_operator_requirement_violation(__a);
  459. _STL_ERROR::__copy_constructor_requirement_violation(__a);
  460. _STL_ERROR::__const_parameter_required_for_copy_constructor(__a,__a);
  461. _STL_ERROR::__const_parameter_required_for_assignment_operator(__a,__a);
  462. }
  463. };
  464. /* DefaultConstructible Requirements */
  465. template <class _Type>
  466. struct _DefaultConstructible_concept_specification {
  467. static void _DefaultConstructible_requirement_violation(_Type __a) {
  468. _STL_ERROR::__default_constructor_requirement_violation(__a);
  469. }
  470. };
  471. /* EqualityComparable Requirements */
  472. template <class _Type>
  473. struct _EqualityComparable_concept_specification {
  474. static void _EqualityComparable_requirement_violation(_Type __a) {
  475. _STL_ERROR::__equality_comparable_requirement_violation(__a, __a);
  476. }
  477. };
  478. /* LessThanComparable Requirements */
  479. template <class _Type>
  480. struct _LessThanComparable_concept_specification {
  481. static void _LessThanComparable_requirement_violation(_Type __a) {
  482. _STL_ERROR::__less_than_comparable_requirement_violation(__a, __a);
  483. }
  484. };
  485. /* TrivialIterator Requirements */
  486. template <class _TrivialIterator>
  487. struct _TrivialIterator_concept_specification {
  488. static void
  489. _TrivialIterator_requirement_violation(_TrivialIterator __i) {
  490. typedef typename
  491. __value_type_type_definition_requirement_violation<_TrivialIterator>::
  492. value_type __T;
  493. // Refinement of Assignable
  494. _Assignable_concept_specification<_TrivialIterator>::
  495. _Assignable_requirement_violation(__i);
  496. // Refinement of DefaultConstructible
  497. _DefaultConstructible_concept_specification<_TrivialIterator>::
  498. _DefaultConstructible_requirement_violation(__i);
  499. // Refinement of EqualityComparable
  500. _EqualityComparable_concept_specification<_TrivialIterator>::
  501. _EqualityComparable_requirement_violation(__i);
  502. // Valid Expressions
  503. _STL_ERROR::__dereference_operator_requirement_violation(__i);
  504. }
  505. };
  506. template <class _TrivialIterator>
  507. struct _Mutable_TrivialIterator_concept_specification {
  508. static void
  509. _Mutable_TrivialIterator_requirement_violation(_TrivialIterator __i) {
  510. _TrivialIterator_concept_specification<_TrivialIterator>::
  511. _TrivialIterator_requirement_violation(__i);
  512. // Valid Expressions
  513. _STL_ERROR::__dereference_operator_and_assignment_requirement_violation(__i);
  514. }
  515. };
  516. /* InputIterator Requirements */
  517. template <class _InputIterator>
  518. struct _InputIterator_concept_specification {
  519. static void
  520. _InputIterator_requirement_violation(_InputIterator __i) {
  521. // Refinement of TrivialIterator
  522. _TrivialIterator_concept_specification<_InputIterator>::
  523. _TrivialIterator_requirement_violation(__i);
  524. // Associated Types
  525. __difference_type_type_definition_requirement_violation<_InputIterator>();
  526. __reference_type_definition_requirement_violation<_InputIterator>();
  527. __pointer_type_definition_requirement_violation<_InputIterator>();
  528. __iterator_category_type_definition_requirement_violation<_InputIterator>();
  529. // Valid Expressions
  530. _STL_ERROR::__preincrement_operator_requirement_violation(__i);
  531. _STL_ERROR::__postincrement_operator_requirement_violation(__i);
  532. }
  533. };
  534. /* OutputIterator Requirements */
  535. template <class _OutputIterator>
  536. struct _OutputIterator_concept_specification {
  537. static void
  538. _OutputIterator_requirement_violation(_OutputIterator __i) {
  539. // Refinement of Assignable
  540. _Assignable_concept_specification<_OutputIterator>::
  541. _Assignable_requirement_violation(__i);
  542. // Associated Types
  543. __iterator_category_type_definition_requirement_violation<_OutputIterator>();
  544. // Valid Expressions
  545. _STL_ERROR::__dereference_operator_requirement_violation(__i);
  546. _STL_ERROR::__preincrement_operator_requirement_violation(__i);
  547. _STL_ERROR::__postincrement_operator_requirement_violation(__i);
  548. _STL_ERROR::
  549. __postincrement_operator_and_assignment_requirement_violation(__i, *__i);
  550. }
  551. };
  552. /* ForwardIterator Requirements */
  553. template <class _ForwardIterator>
  554. struct _ForwardIterator_concept_specification {
  555. static void
  556. _ForwardIterator_requirement_violation(_ForwardIterator __i) {
  557. // Refinement of InputIterator
  558. _InputIterator_concept_specification<_ForwardIterator>::
  559. _InputIterator_requirement_violation(__i);
  560. }
  561. };
  562. template <class _ForwardIterator>
  563. struct _Mutable_ForwardIterator_concept_specification {
  564. static void
  565. _Mutable_ForwardIterator_requirement_violation(_ForwardIterator __i) {
  566. _ForwardIterator_concept_specification<_ForwardIterator>::
  567. _ForwardIterator_requirement_violation(__i);
  568. // Refinement of OutputIterator
  569. _OutputIterator_concept_specification<_ForwardIterator>::
  570. _OutputIterator_requirement_violation(__i);
  571. }
  572. };
  573. /* BidirectionalIterator Requirements */
  574. template <class _BidirectionalIterator>
  575. struct _BidirectionalIterator_concept_specification {
  576. static void
  577. _BidirectionalIterator_requirement_violation(_BidirectionalIterator __i) {
  578. // Refinement of ForwardIterator
  579. _ForwardIterator_concept_specification<_BidirectionalIterator>::
  580. _ForwardIterator_requirement_violation(__i);
  581. // Valid Expressions
  582. _STL_ERROR::__predecrement_operator_requirement_violation(__i);
  583. _STL_ERROR::__postdecrement_operator_requirement_violation(__i);
  584. }
  585. };
  586. template <class _BidirectionalIterator>
  587. struct _Mutable_BidirectionalIterator_concept_specification {
  588. static void
  589. _Mutable_BidirectionalIterator_requirement_violation(
  590. _BidirectionalIterator __i)
  591. {
  592. _BidirectionalIterator_concept_specification<_BidirectionalIterator>::
  593. _BidirectionalIterator_requirement_violation(__i);
  594. // Refinement of mutable_ForwardIterator
  595. _Mutable_ForwardIterator_concept_specification<_BidirectionalIterator>::
  596. _Mutable_ForwardIterator_requirement_violation(__i);
  597. typedef typename
  598. __value_type_type_definition_requirement_violation<
  599. _BidirectionalIterator>::value_type __T;
  600. typename _Mutable_trait<__T>::_Type* __tmp_ptr = 0;
  601. // Valid Expressions
  602. _STL_ERROR::
  603. __postincrement_operator_and_assignment_requirement_violation(__i,
  604. *__tmp_ptr);
  605. }
  606. };
  607. /* RandomAccessIterator Requirements */
  608. template <class _RandAccIter>
  609. struct _RandomAccessIterator_concept_specification {
  610. static void
  611. _RandomAccessIterator_requirement_violation(_RandAccIter __i) {
  612. // Refinement of BidirectionalIterator
  613. _BidirectionalIterator_concept_specification<_RandAccIter>::
  614. _BidirectionalIterator_requirement_violation(__i);
  615. // Refinement of LessThanComparable
  616. _LessThanComparable_concept_specification<_RandAccIter>::
  617. _LessThanComparable_requirement_violation(__i);
  618. typedef typename
  619. __value_type_type_definition_requirement_violation<_RandAccIter>
  620. ::value_type
  621. value_type;
  622. typedef typename
  623. __difference_type_type_definition_requirement_violation<_RandAccIter>
  624. ::difference_type
  625. _Dist;
  626. typedef typename _Mutable_trait<_Dist>::_Type _MutDist;
  627. // Valid Expressions
  628. _STL_ERROR::__iterator_addition_assignment_requirement_violation(__i,
  629. _MutDist());
  630. _STL_ERROR::__iterator_addition_requirement_violation(__i,
  631. _MutDist());
  632. _STL_ERROR::
  633. __iterator_subtraction_assignment_requirement_violation(__i,
  634. _MutDist());
  635. _STL_ERROR::__iterator_subtraction_requirement_violation(__i,
  636. _MutDist());
  637. _STL_ERROR::__difference_operator_requirement_violation(__i, __i,
  638. _MutDist());
  639. typename _Mutable_trait<value_type>::_Type* __dummy_ptr = 0;
  640. _STL_ERROR::__element_access_operator_requirement_violation(__i,
  641. __dummy_ptr,
  642. _MutDist());
  643. }
  644. };
  645. template <class _RandAccIter>
  646. struct _Mutable_RandomAccessIterator_concept_specification {
  647. static void
  648. _Mutable_RandomAccessIterator_requirement_violation(_RandAccIter __i)
  649. {
  650. _RandomAccessIterator_concept_specification<_RandAccIter>::
  651. _RandomAccessIterator_requirement_violation(__i);
  652. // Refinement of mutable_BidirectionalIterator
  653. _Mutable_BidirectionalIterator_concept_specification<_RandAccIter>::
  654. _Mutable_BidirectionalIterator_requirement_violation(__i);
  655. typedef typename
  656. __value_type_type_definition_requirement_violation<_RandAccIter>
  657. ::value_type
  658. value_type;
  659. typedef typename
  660. __difference_type_type_definition_requirement_violation<_RandAccIter>
  661. ::difference_type
  662. _Dist;
  663. typename _Mutable_trait<value_type>::_Type* __tmp_ptr = 0;
  664. // Valid Expressions
  665. _STL_ERROR::__element_assignment_operator_requirement_violation(__i,
  666. __tmp_ptr, _Dist());
  667. }
  668. };
  669. #define _STLP_TYPEDEF_REQUIREMENT(__REQUIREMENT) \
  670. template <class Type> \
  671. struct __##__REQUIREMENT##__typedef_requirement_violation { \
  672. typedef typename Type::__REQUIREMENT __REQUIREMENT; \
  673. };
  674. _STLP_TYPEDEF_REQUIREMENT(value_type);
  675. _STLP_TYPEDEF_REQUIREMENT(difference_type);
  676. _STLP_TYPEDEF_REQUIREMENT(size_type);
  677. _STLP_TYPEDEF_REQUIREMENT(reference);
  678. _STLP_TYPEDEF_REQUIREMENT(const_reference);
  679. _STLP_TYPEDEF_REQUIREMENT(pointer);
  680. _STLP_TYPEDEF_REQUIREMENT(const_pointer);
  681. template <class _Alloc>
  682. struct _Allocator_concept_specification {
  683. static void
  684. _Allocator_requirement_violation(_Alloc __a) {
  685. // Refinement of DefaultConstructible
  686. _DefaultConstructible_concept_specification<_Alloc>::
  687. _DefaultConstructible_requirement_violation(__a);
  688. // Refinement of EqualityComparable
  689. _EqualityComparable_concept_specification<_Alloc>::
  690. _EqualityComparable_requirement_violation(__a);
  691. // Associated Types
  692. __value_type__typedef_requirement_violation<_Alloc>();
  693. __difference_type__typedef_requirement_violation<_Alloc>();
  694. __size_type__typedef_requirement_violation<_Alloc>();
  695. __reference__typedef_requirement_violation<_Alloc>();
  696. __const_reference__typedef_requirement_violation<_Alloc>();
  697. __pointer__typedef_requirement_violation<_Alloc>();
  698. __const_pointer__typedef_requirement_violation<_Alloc>();
  699. typedef typename _Alloc::value_type _Type;
  700. _STLP_REQUIRES_SAME_TYPE(typename _Alloc::rebind<_Type>::other, _Alloc);
  701. }
  702. };
  703. #endif /* _STLP_USE_CONCEPT_CHECKS */
  704. #endif /* __CONCEPT_CHECKS_H */
  705. // Local Variables:
  706. // mode:C++
  707. // End: