concept_archetype.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. //
  2. // (C) Copyright Jeremy Siek 2000.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Revision History:
  8. //
  9. // 17 July 2001: Added const to some member functions. (Jeremy Siek)
  10. // 05 May 2001: Removed static dummy_cons object. (Jeremy Siek)
  11. // See http://www.boost.org/libs/concept_check for documentation.
  12. #ifndef BOOST_CONCEPT_ARCHETYPES_HPP
  13. #define BOOST_CONCEPT_ARCHETYPES_HPP
  14. #include <boost/config.hpp>
  15. #include <boost/config/workaround.hpp>
  16. #include <functional>
  17. #include <iterator> // iterator tags
  18. #include <cstddef> // std::ptrdiff_t
  19. namespace boost {
  20. //===========================================================================
  21. // Basic Archetype Classes
  22. namespace detail {
  23. class dummy_constructor { };
  24. }
  25. // A type that models no concept. The template parameter
  26. // is only there so that null_archetype types can be created
  27. // that have different type.
  28. template <class T = int>
  29. class null_archetype {
  30. private:
  31. null_archetype() { }
  32. null_archetype(const null_archetype&) { }
  33. null_archetype& operator=(const null_archetype&) { return *this; }
  34. public:
  35. null_archetype(detail::dummy_constructor) { }
  36. #ifndef __MWERKS__
  37. template <class TT>
  38. friend void dummy_friend(); // just to avoid warnings
  39. #endif
  40. };
  41. // This is a helper class that provides a way to get a reference to
  42. // an object. The get() function will never be called at run-time
  43. // (nothing in this file will) so this seemingly very bad function
  44. // is really quite innocent. The name of this class needs to be
  45. // changed.
  46. template <class T>
  47. class static_object
  48. {
  49. public:
  50. static T& get()
  51. {
  52. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  53. return *reinterpret_cast<T*>(0);
  54. #else
  55. static char d[sizeof(T)];
  56. return *reinterpret_cast<T*>(d);
  57. #endif
  58. }
  59. };
  60. template <class Base = null_archetype<> >
  61. class default_constructible_archetype : public Base {
  62. public:
  63. default_constructible_archetype()
  64. : Base(static_object<detail::dummy_constructor>::get()) { }
  65. default_constructible_archetype(detail::dummy_constructor x) : Base(x) { }
  66. };
  67. template <class Base = null_archetype<> >
  68. class assignable_archetype : public Base {
  69. assignable_archetype() { }
  70. assignable_archetype(const assignable_archetype&) { }
  71. public:
  72. assignable_archetype& operator=(const assignable_archetype&) {
  73. return *this;
  74. }
  75. assignable_archetype(detail::dummy_constructor x) : Base(x) { }
  76. };
  77. template <class Base = null_archetype<> >
  78. class copy_constructible_archetype : public Base {
  79. public:
  80. copy_constructible_archetype()
  81. : Base(static_object<detail::dummy_constructor>::get()) { }
  82. copy_constructible_archetype(const copy_constructible_archetype&)
  83. : Base(static_object<detail::dummy_constructor>::get()) { }
  84. copy_constructible_archetype(detail::dummy_constructor x) : Base(x) { }
  85. };
  86. template <class Base = null_archetype<> >
  87. class sgi_assignable_archetype : public Base {
  88. public:
  89. sgi_assignable_archetype(const sgi_assignable_archetype&)
  90. : Base(static_object<detail::dummy_constructor>::get()) { }
  91. sgi_assignable_archetype& operator=(const sgi_assignable_archetype&) {
  92. return *this;
  93. }
  94. sgi_assignable_archetype(const detail::dummy_constructor& x) : Base(x) { }
  95. };
  96. struct default_archetype_base {
  97. default_archetype_base(detail::dummy_constructor) { }
  98. };
  99. // Careful, don't use same type for T and Base. That results in the
  100. // conversion operator being invalid. Since T is often
  101. // null_archetype, can't use null_archetype for Base.
  102. template <class T, class Base = default_archetype_base>
  103. class convertible_to_archetype : public Base {
  104. private:
  105. convertible_to_archetype() { }
  106. convertible_to_archetype(const convertible_to_archetype& ) { }
  107. convertible_to_archetype& operator=(const convertible_to_archetype&)
  108. { return *this; }
  109. public:
  110. convertible_to_archetype(detail::dummy_constructor x) : Base(x) { }
  111. operator const T&() const { return static_object<T>::get(); }
  112. };
  113. template <class T, class Base = default_archetype_base>
  114. class convertible_from_archetype : public Base {
  115. private:
  116. convertible_from_archetype() { }
  117. convertible_from_archetype(const convertible_from_archetype& ) { }
  118. convertible_from_archetype& operator=(const convertible_from_archetype&)
  119. { return *this; }
  120. public:
  121. convertible_from_archetype(detail::dummy_constructor x) : Base(x) { }
  122. convertible_from_archetype(const T&) { }
  123. convertible_from_archetype& operator=(const T&)
  124. { return *this; }
  125. };
  126. class boolean_archetype {
  127. public:
  128. boolean_archetype(const boolean_archetype&) { }
  129. operator bool() const { return true; }
  130. boolean_archetype(detail::dummy_constructor) { }
  131. private:
  132. boolean_archetype() { }
  133. boolean_archetype& operator=(const boolean_archetype&) { return *this; }
  134. };
  135. template <class Base = null_archetype<> >
  136. class equality_comparable_archetype : public Base {
  137. public:
  138. equality_comparable_archetype(detail::dummy_constructor x) : Base(x) { }
  139. };
  140. template <class Base>
  141. boolean_archetype
  142. operator==(const equality_comparable_archetype<Base>&,
  143. const equality_comparable_archetype<Base>&)
  144. {
  145. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  146. }
  147. template <class Base>
  148. boolean_archetype
  149. operator!=(const equality_comparable_archetype<Base>&,
  150. const equality_comparable_archetype<Base>&)
  151. {
  152. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  153. }
  154. template <class Base = null_archetype<> >
  155. class equality_comparable2_first_archetype : public Base {
  156. public:
  157. equality_comparable2_first_archetype(detail::dummy_constructor x)
  158. : Base(x) { }
  159. };
  160. template <class Base = null_archetype<> >
  161. class equality_comparable2_second_archetype : public Base {
  162. public:
  163. equality_comparable2_second_archetype(detail::dummy_constructor x)
  164. : Base(x) { }
  165. };
  166. template <class Base1, class Base2>
  167. boolean_archetype
  168. operator==(const equality_comparable2_first_archetype<Base1>&,
  169. const equality_comparable2_second_archetype<Base2>&)
  170. {
  171. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  172. }
  173. template <class Base1, class Base2>
  174. boolean_archetype
  175. operator!=(const equality_comparable2_first_archetype<Base1>&,
  176. const equality_comparable2_second_archetype<Base2>&)
  177. {
  178. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  179. }
  180. template <class Base = null_archetype<> >
  181. class less_than_comparable_archetype : public Base {
  182. public:
  183. less_than_comparable_archetype(detail::dummy_constructor x) : Base(x) { }
  184. };
  185. template <class Base>
  186. boolean_archetype
  187. operator<(const less_than_comparable_archetype<Base>&,
  188. const less_than_comparable_archetype<Base>&)
  189. {
  190. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  191. }
  192. template <class Base = null_archetype<> >
  193. class comparable_archetype : public Base {
  194. public:
  195. comparable_archetype(detail::dummy_constructor x) : Base(x) { }
  196. };
  197. template <class Base>
  198. boolean_archetype
  199. operator<(const comparable_archetype<Base>&,
  200. const comparable_archetype<Base>&)
  201. {
  202. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  203. }
  204. template <class Base>
  205. boolean_archetype
  206. operator<=(const comparable_archetype<Base>&,
  207. const comparable_archetype<Base>&)
  208. {
  209. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  210. }
  211. template <class Base>
  212. boolean_archetype
  213. operator>(const comparable_archetype<Base>&,
  214. const comparable_archetype<Base>&)
  215. {
  216. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  217. }
  218. template <class Base>
  219. boolean_archetype
  220. operator>=(const comparable_archetype<Base>&,
  221. const comparable_archetype<Base>&)
  222. {
  223. return boolean_archetype(static_object<detail::dummy_constructor>::get());
  224. }
  225. // The purpose of the optags is so that one can specify
  226. // exactly which types the operator< is defined between.
  227. // This is useful for allowing the operations:
  228. //
  229. // A a; B b;
  230. // a < b
  231. // b < a
  232. //
  233. // without also allowing the combinations:
  234. //
  235. // a < a
  236. // b < b
  237. //
  238. struct optag1 { };
  239. struct optag2 { };
  240. struct optag3 { };
  241. #define BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(OP, NAME) \
  242. template <class Base = null_archetype<>, class Tag = optag1 > \
  243. class NAME##_first_archetype : public Base { \
  244. public: \
  245. NAME##_first_archetype(detail::dummy_constructor x) : Base(x) { } \
  246. }; \
  247. \
  248. template <class Base = null_archetype<>, class Tag = optag1 > \
  249. class NAME##_second_archetype : public Base { \
  250. public: \
  251. NAME##_second_archetype(detail::dummy_constructor x) : Base(x) { } \
  252. }; \
  253. \
  254. template <class BaseFirst, class BaseSecond, class Tag> \
  255. boolean_archetype \
  256. operator OP (const NAME##_first_archetype<BaseFirst, Tag>&, \
  257. const NAME##_second_archetype<BaseSecond, Tag>&) \
  258. { \
  259. return boolean_archetype(static_object<detail::dummy_constructor>::get()); \
  260. }
  261. BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(==, equal_op)
  262. BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(!=, not_equal_op)
  263. BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(<, less_than_op)
  264. BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(<=, less_equal_op)
  265. BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(>, greater_than_op)
  266. BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(>=, greater_equal_op)
  267. #define BOOST_DEFINE_OPERATOR_ARCHETYPE(OP, NAME) \
  268. template <class Base = null_archetype<> > \
  269. class NAME##_archetype : public Base { \
  270. public: \
  271. NAME##_archetype(detail::dummy_constructor x) : Base(x) { } \
  272. NAME##_archetype(const NAME##_archetype&) \
  273. : Base(static_object<detail::dummy_constructor>::get()) { } \
  274. NAME##_archetype& operator=(const NAME##_archetype&) { return *this; } \
  275. }; \
  276. template <class Base> \
  277. NAME##_archetype<Base> \
  278. operator OP (const NAME##_archetype<Base>&,\
  279. const NAME##_archetype<Base>&) \
  280. { \
  281. return \
  282. NAME##_archetype<Base>(static_object<detail::dummy_constructor>::get()); \
  283. }
  284. BOOST_DEFINE_OPERATOR_ARCHETYPE(+, addable)
  285. BOOST_DEFINE_OPERATOR_ARCHETYPE(-, subtractable)
  286. BOOST_DEFINE_OPERATOR_ARCHETYPE(*, multipliable)
  287. BOOST_DEFINE_OPERATOR_ARCHETYPE(/, dividable)
  288. BOOST_DEFINE_OPERATOR_ARCHETYPE(%, modable)
  289. // As is, these are useless because of the return type.
  290. // Need to invent a better way...
  291. #define BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(OP, NAME) \
  292. template <class Return, class Base = null_archetype<> > \
  293. class NAME##_first_archetype : public Base { \
  294. public: \
  295. NAME##_first_archetype(detail::dummy_constructor x) : Base(x) { } \
  296. }; \
  297. \
  298. template <class Return, class Base = null_archetype<> > \
  299. class NAME##_second_archetype : public Base { \
  300. public: \
  301. NAME##_second_archetype(detail::dummy_constructor x) : Base(x) { } \
  302. }; \
  303. \
  304. template <class Return, class BaseFirst, class BaseSecond> \
  305. Return \
  306. operator OP (const NAME##_first_archetype<Return, BaseFirst>&, \
  307. const NAME##_second_archetype<Return, BaseSecond>&) \
  308. { \
  309. return Return(static_object<detail::dummy_constructor>::get()); \
  310. }
  311. BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(+, plus_op)
  312. BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(*, time_op)
  313. BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(/, divide_op)
  314. BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(-, subtract_op)
  315. BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(%, mod_op)
  316. //===========================================================================
  317. // Function Object Archetype Classes
  318. template <class Return>
  319. class generator_archetype {
  320. public:
  321. const Return& operator()() {
  322. return static_object<Return>::get();
  323. }
  324. };
  325. class void_generator_archetype {
  326. public:
  327. void operator()() { }
  328. };
  329. template <class Arg, class Return>
  330. class unary_function_archetype {
  331. private:
  332. unary_function_archetype() { }
  333. public:
  334. unary_function_archetype(detail::dummy_constructor) { }
  335. const Return& operator()(const Arg&) const {
  336. return static_object<Return>::get();
  337. }
  338. };
  339. template <class Arg1, class Arg2, class Return>
  340. class binary_function_archetype {
  341. private:
  342. binary_function_archetype() { }
  343. public:
  344. binary_function_archetype(detail::dummy_constructor) { }
  345. const Return& operator()(const Arg1&, const Arg2&) const {
  346. return static_object<Return>::get();
  347. }
  348. };
  349. template <class Arg>
  350. class unary_predicate_archetype {
  351. typedef boolean_archetype Return;
  352. unary_predicate_archetype() { }
  353. public:
  354. unary_predicate_archetype(detail::dummy_constructor) { }
  355. const Return& operator()(const Arg&) const {
  356. return static_object<Return>::get();
  357. }
  358. };
  359. template <class Arg1, class Arg2, class Base = null_archetype<> >
  360. class binary_predicate_archetype {
  361. typedef boolean_archetype Return;
  362. binary_predicate_archetype() { }
  363. public:
  364. binary_predicate_archetype(detail::dummy_constructor) { }
  365. const Return& operator()(const Arg1&, const Arg2&) const {
  366. return static_object<Return>::get();
  367. }
  368. };
  369. //===========================================================================
  370. // Iterator Archetype Classes
  371. template <class T, int I = 0>
  372. class input_iterator_archetype
  373. {
  374. private:
  375. typedef input_iterator_archetype self;
  376. public:
  377. typedef std::input_iterator_tag iterator_category;
  378. typedef T value_type;
  379. struct reference {
  380. operator const value_type&() const { return static_object<T>::get(); }
  381. };
  382. typedef const T* pointer;
  383. typedef std::ptrdiff_t difference_type;
  384. self& operator=(const self&) { return *this; }
  385. bool operator==(const self&) const { return true; }
  386. bool operator!=(const self&) const { return true; }
  387. reference operator*() const { return reference(); }
  388. self& operator++() { return *this; }
  389. self operator++(int) { return *this; }
  390. };
  391. template <class T>
  392. class input_iterator_archetype_no_proxy
  393. {
  394. private:
  395. typedef input_iterator_archetype_no_proxy self;
  396. public:
  397. typedef std::input_iterator_tag iterator_category;
  398. typedef T value_type;
  399. typedef const T& reference;
  400. typedef const T* pointer;
  401. typedef std::ptrdiff_t difference_type;
  402. self& operator=(const self&) { return *this; }
  403. bool operator==(const self&) const { return true; }
  404. bool operator!=(const self&) const { return true; }
  405. reference operator*() const { return static_object<T>::get(); }
  406. self& operator++() { return *this; }
  407. self operator++(int) { return *this; }
  408. };
  409. template <class T>
  410. struct output_proxy {
  411. output_proxy& operator=(const T&) { return *this; }
  412. };
  413. template <class T>
  414. class output_iterator_archetype
  415. {
  416. public:
  417. typedef output_iterator_archetype self;
  418. public:
  419. typedef std::output_iterator_tag iterator_category;
  420. typedef output_proxy<T> value_type;
  421. typedef output_proxy<T> reference;
  422. typedef void pointer;
  423. typedef void difference_type;
  424. output_iterator_archetype(detail::dummy_constructor) { }
  425. output_iterator_archetype(const self&) { }
  426. self& operator=(const self&) { return *this; }
  427. bool operator==(const self&) const { return true; }
  428. bool operator!=(const self&) const { return true; }
  429. reference operator*() const { return output_proxy<T>(); }
  430. self& operator++() { return *this; }
  431. self operator++(int) { return *this; }
  432. private:
  433. output_iterator_archetype() { }
  434. };
  435. template <class T>
  436. class input_output_iterator_archetype
  437. {
  438. private:
  439. typedef input_output_iterator_archetype self;
  440. struct in_out_tag : public std::input_iterator_tag, public std::output_iterator_tag { };
  441. public:
  442. typedef in_out_tag iterator_category;
  443. typedef T value_type;
  444. struct reference {
  445. reference& operator=(const T&) { return *this; }
  446. operator value_type() { return static_object<T>::get(); }
  447. };
  448. typedef const T* pointer;
  449. typedef std::ptrdiff_t difference_type;
  450. input_output_iterator_archetype() { }
  451. self& operator=(const self&) { return *this; }
  452. bool operator==(const self&) const { return true; }
  453. bool operator!=(const self&) const { return true; }
  454. reference operator*() const { return reference(); }
  455. self& operator++() { return *this; }
  456. self operator++(int) { return *this; }
  457. };
  458. template <class T>
  459. class forward_iterator_archetype
  460. {
  461. public:
  462. typedef forward_iterator_archetype self;
  463. public:
  464. typedef std::forward_iterator_tag iterator_category;
  465. typedef T value_type;
  466. typedef const T& reference;
  467. typedef T const* pointer;
  468. typedef std::ptrdiff_t difference_type;
  469. forward_iterator_archetype() { }
  470. self& operator=(const self&) { return *this; }
  471. bool operator==(const self&) const { return true; }
  472. bool operator!=(const self&) const { return true; }
  473. reference operator*() const { return static_object<T>::get(); }
  474. self& operator++() { return *this; }
  475. self operator++(int) { return *this; }
  476. };
  477. template <class T>
  478. class mutable_forward_iterator_archetype
  479. {
  480. public:
  481. typedef mutable_forward_iterator_archetype self;
  482. public:
  483. typedef std::forward_iterator_tag iterator_category;
  484. typedef T value_type;
  485. typedef T& reference;
  486. typedef T* pointer;
  487. typedef std::ptrdiff_t difference_type;
  488. mutable_forward_iterator_archetype() { }
  489. self& operator=(const self&) { return *this; }
  490. bool operator==(const self&) const { return true; }
  491. bool operator!=(const self&) const { return true; }
  492. reference operator*() const { return static_object<T>::get(); }
  493. self& operator++() { return *this; }
  494. self operator++(int) { return *this; }
  495. };
  496. template <class T>
  497. class bidirectional_iterator_archetype
  498. {
  499. public:
  500. typedef bidirectional_iterator_archetype self;
  501. public:
  502. typedef std::bidirectional_iterator_tag iterator_category;
  503. typedef T value_type;
  504. typedef const T& reference;
  505. typedef T* pointer;
  506. typedef std::ptrdiff_t difference_type;
  507. bidirectional_iterator_archetype() { }
  508. self& operator=(const self&) { return *this; }
  509. bool operator==(const self&) const { return true; }
  510. bool operator!=(const self&) const { return true; }
  511. reference operator*() const { return static_object<T>::get(); }
  512. self& operator++() { return *this; }
  513. self operator++(int) { return *this; }
  514. self& operator--() { return *this; }
  515. self operator--(int) { return *this; }
  516. };
  517. template <class T>
  518. class mutable_bidirectional_iterator_archetype
  519. {
  520. public:
  521. typedef mutable_bidirectional_iterator_archetype self;
  522. public:
  523. typedef std::bidirectional_iterator_tag iterator_category;
  524. typedef T value_type;
  525. typedef T& reference;
  526. typedef T* pointer;
  527. typedef std::ptrdiff_t difference_type;
  528. mutable_bidirectional_iterator_archetype() { }
  529. self& operator=(const self&) { return *this; }
  530. bool operator==(const self&) const { return true; }
  531. bool operator!=(const self&) const { return true; }
  532. reference operator*() const { return static_object<T>::get(); }
  533. self& operator++() { return *this; }
  534. self operator++(int) { return *this; }
  535. self& operator--() { return *this; }
  536. self operator--(int) { return *this; }
  537. };
  538. template <class T>
  539. class random_access_iterator_archetype
  540. {
  541. public:
  542. typedef random_access_iterator_archetype self;
  543. public:
  544. typedef std::random_access_iterator_tag iterator_category;
  545. typedef T value_type;
  546. typedef const T& reference;
  547. typedef T* pointer;
  548. typedef std::ptrdiff_t difference_type;
  549. random_access_iterator_archetype() { }
  550. self& operator=(const self&) { return *this; }
  551. bool operator==(const self&) const { return true; }
  552. bool operator!=(const self&) const { return true; }
  553. reference operator*() const { return static_object<T>::get(); }
  554. self& operator++() { return *this; }
  555. self operator++(int) { return *this; }
  556. self& operator--() { return *this; }
  557. self operator--(int) { return *this; }
  558. reference operator[](difference_type) const
  559. { return static_object<T>::get(); }
  560. self& operator+=(difference_type) { return *this; }
  561. self& operator-=(difference_type) { return *this; }
  562. difference_type operator-(const self&) const
  563. { return difference_type(); }
  564. self operator+(difference_type) const { return *this; }
  565. self operator-(difference_type) const { return *this; }
  566. bool operator<(const self&) const { return true; }
  567. bool operator<=(const self&) const { return true; }
  568. bool operator>(const self&) const { return true; }
  569. bool operator>=(const self&) const { return true; }
  570. };
  571. template <class T>
  572. random_access_iterator_archetype<T>
  573. operator+(typename random_access_iterator_archetype<T>::difference_type,
  574. const random_access_iterator_archetype<T>& x)
  575. { return x; }
  576. template <class T>
  577. class mutable_random_access_iterator_archetype
  578. {
  579. public:
  580. typedef mutable_random_access_iterator_archetype self;
  581. public:
  582. typedef std::random_access_iterator_tag iterator_category;
  583. typedef T value_type;
  584. typedef T& reference;
  585. typedef T* pointer;
  586. typedef std::ptrdiff_t difference_type;
  587. mutable_random_access_iterator_archetype() { }
  588. self& operator=(const self&) { return *this; }
  589. bool operator==(const self&) const { return true; }
  590. bool operator!=(const self&) const { return true; }
  591. reference operator*() const { return static_object<T>::get(); }
  592. self& operator++() { return *this; }
  593. self operator++(int) { return *this; }
  594. self& operator--() { return *this; }
  595. self operator--(int) { return *this; }
  596. reference operator[](difference_type) const
  597. { return static_object<T>::get(); }
  598. self& operator+=(difference_type) { return *this; }
  599. self& operator-=(difference_type) { return *this; }
  600. difference_type operator-(const self&) const
  601. { return difference_type(); }
  602. self operator+(difference_type) const { return *this; }
  603. self operator-(difference_type) const { return *this; }
  604. bool operator<(const self&) const { return true; }
  605. bool operator<=(const self&) const { return true; }
  606. bool operator>(const self&) const { return true; }
  607. bool operator>=(const self&) const { return true; }
  608. };
  609. template <class T>
  610. mutable_random_access_iterator_archetype<T>
  611. operator+
  612. (typename mutable_random_access_iterator_archetype<T>::difference_type,
  613. const mutable_random_access_iterator_archetype<T>& x)
  614. { return x; }
  615. } // namespace boost
  616. #endif // BOOST_CONCEPT_ARCHETYPES_H