iterators.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012.
  4. // (C) Copyright Gennaro Prota 2003 - 2004.
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/container for documentation.
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13. #ifndef BOOST_CONTAINER_DETAIL_ITERATORS_HPP
  14. #define BOOST_CONTAINER_DETAIL_ITERATORS_HPP
  15. #if defined(_MSC_VER)
  16. # pragma once
  17. #endif
  18. #include "config_begin.hpp"
  19. #include <boost/container/detail/workaround.hpp>
  20. #include <boost/move/utility.hpp>
  21. #include <boost/container/allocator_traits.hpp>
  22. #include <boost/container/detail/type_traits.hpp>
  23. #include <boost/static_assert.hpp>
  24. #ifdef BOOST_CONTAINER_PERFECT_FORWARDING
  25. #include <boost/container/detail/variadic_templates_tools.hpp>
  26. #else
  27. #include <boost/container/detail/preprocessor.hpp>
  28. #endif
  29. #include <iterator>
  30. namespace boost {
  31. namespace container {
  32. template <class T, class Difference = std::ptrdiff_t>
  33. class constant_iterator
  34. : public std::iterator
  35. <std::random_access_iterator_tag, T, Difference, const T*, const T &>
  36. {
  37. typedef constant_iterator<T, Difference> this_type;
  38. public:
  39. explicit constant_iterator(const T &ref, Difference range_size)
  40. : m_ptr(&ref), m_num(range_size){}
  41. //Constructors
  42. constant_iterator()
  43. : m_ptr(0), m_num(0){}
  44. constant_iterator& operator++()
  45. { increment(); return *this; }
  46. constant_iterator operator++(int)
  47. {
  48. constant_iterator result (*this);
  49. increment();
  50. return result;
  51. }
  52. constant_iterator& operator--()
  53. { decrement(); return *this; }
  54. constant_iterator operator--(int)
  55. {
  56. constant_iterator result (*this);
  57. decrement();
  58. return result;
  59. }
  60. friend bool operator== (const constant_iterator& i, const constant_iterator& i2)
  61. { return i.equal(i2); }
  62. friend bool operator!= (const constant_iterator& i, const constant_iterator& i2)
  63. { return !(i == i2); }
  64. friend bool operator< (const constant_iterator& i, const constant_iterator& i2)
  65. { return i.less(i2); }
  66. friend bool operator> (const constant_iterator& i, const constant_iterator& i2)
  67. { return i2 < i; }
  68. friend bool operator<= (const constant_iterator& i, const constant_iterator& i2)
  69. { return !(i > i2); }
  70. friend bool operator>= (const constant_iterator& i, const constant_iterator& i2)
  71. { return !(i < i2); }
  72. friend Difference operator- (const constant_iterator& i, const constant_iterator& i2)
  73. { return i2.distance_to(i); }
  74. //Arithmetic
  75. constant_iterator& operator+=(Difference off)
  76. { this->advance(off); return *this; }
  77. constant_iterator operator+(Difference off) const
  78. {
  79. constant_iterator other(*this);
  80. other.advance(off);
  81. return other;
  82. }
  83. friend constant_iterator operator+(Difference off, const constant_iterator& right)
  84. { return right + off; }
  85. constant_iterator& operator-=(Difference off)
  86. { this->advance(-off); return *this; }
  87. constant_iterator operator-(Difference off) const
  88. { return *this + (-off); }
  89. const T& operator*() const
  90. { return dereference(); }
  91. const T& operator[] (Difference ) const
  92. { return dereference(); }
  93. const T* operator->() const
  94. { return &(dereference()); }
  95. private:
  96. const T * m_ptr;
  97. Difference m_num;
  98. void increment()
  99. { --m_num; }
  100. void decrement()
  101. { ++m_num; }
  102. bool equal(const this_type &other) const
  103. { return m_num == other.m_num; }
  104. bool less(const this_type &other) const
  105. { return other.m_num < m_num; }
  106. const T & dereference() const
  107. { return *m_ptr; }
  108. void advance(Difference n)
  109. { m_num -= n; }
  110. Difference distance_to(const this_type &other)const
  111. { return m_num - other.m_num; }
  112. };
  113. template <class T, class Difference = std::ptrdiff_t>
  114. class value_init_construct_iterator
  115. : public std::iterator
  116. <std::random_access_iterator_tag, T, Difference, const T*, const T &>
  117. {
  118. typedef value_init_construct_iterator<T, Difference> this_type;
  119. public:
  120. explicit value_init_construct_iterator(Difference range_size)
  121. : m_num(range_size){}
  122. //Constructors
  123. value_init_construct_iterator()
  124. : m_num(0){}
  125. value_init_construct_iterator& operator++()
  126. { increment(); return *this; }
  127. value_init_construct_iterator operator++(int)
  128. {
  129. value_init_construct_iterator result (*this);
  130. increment();
  131. return result;
  132. }
  133. value_init_construct_iterator& operator--()
  134. { decrement(); return *this; }
  135. value_init_construct_iterator operator--(int)
  136. {
  137. value_init_construct_iterator result (*this);
  138. decrement();
  139. return result;
  140. }
  141. friend bool operator== (const value_init_construct_iterator& i, const value_init_construct_iterator& i2)
  142. { return i.equal(i2); }
  143. friend bool operator!= (const value_init_construct_iterator& i, const value_init_construct_iterator& i2)
  144. { return !(i == i2); }
  145. friend bool operator< (const value_init_construct_iterator& i, const value_init_construct_iterator& i2)
  146. { return i.less(i2); }
  147. friend bool operator> (const value_init_construct_iterator& i, const value_init_construct_iterator& i2)
  148. { return i2 < i; }
  149. friend bool operator<= (const value_init_construct_iterator& i, const value_init_construct_iterator& i2)
  150. { return !(i > i2); }
  151. friend bool operator>= (const value_init_construct_iterator& i, const value_init_construct_iterator& i2)
  152. { return !(i < i2); }
  153. friend Difference operator- (const value_init_construct_iterator& i, const value_init_construct_iterator& i2)
  154. { return i2.distance_to(i); }
  155. //Arithmetic
  156. value_init_construct_iterator& operator+=(Difference off)
  157. { this->advance(off); return *this; }
  158. value_init_construct_iterator operator+(Difference off) const
  159. {
  160. value_init_construct_iterator other(*this);
  161. other.advance(off);
  162. return other;
  163. }
  164. friend value_init_construct_iterator operator+(Difference off, const value_init_construct_iterator& right)
  165. { return right + off; }
  166. value_init_construct_iterator& operator-=(Difference off)
  167. { this->advance(-off); return *this; }
  168. value_init_construct_iterator operator-(Difference off) const
  169. { return *this + (-off); }
  170. //This pseudo-iterator's dereference operations have no sense since value is not
  171. //constructed until ::boost::container::construct_in_place is called.
  172. //So comment them to catch bad uses
  173. //const T& operator*() const;
  174. //const T& operator[](difference_type) const;
  175. //const T* operator->() const;
  176. private:
  177. Difference m_num;
  178. void increment()
  179. { --m_num; }
  180. void decrement()
  181. { ++m_num; }
  182. bool equal(const this_type &other) const
  183. { return m_num == other.m_num; }
  184. bool less(const this_type &other) const
  185. { return other.m_num < m_num; }
  186. const T & dereference() const
  187. {
  188. static T dummy;
  189. return dummy;
  190. }
  191. void advance(Difference n)
  192. { m_num -= n; }
  193. Difference distance_to(const this_type &other)const
  194. { return m_num - other.m_num; }
  195. };
  196. template <class T, class Difference = std::ptrdiff_t>
  197. class default_init_construct_iterator
  198. : public std::iterator
  199. <std::random_access_iterator_tag, T, Difference, const T*, const T &>
  200. {
  201. typedef default_init_construct_iterator<T, Difference> this_type;
  202. public:
  203. explicit default_init_construct_iterator(Difference range_size)
  204. : m_num(range_size){}
  205. //Constructors
  206. default_init_construct_iterator()
  207. : m_num(0){}
  208. default_init_construct_iterator& operator++()
  209. { increment(); return *this; }
  210. default_init_construct_iterator operator++(int)
  211. {
  212. default_init_construct_iterator result (*this);
  213. increment();
  214. return result;
  215. }
  216. default_init_construct_iterator& operator--()
  217. { decrement(); return *this; }
  218. default_init_construct_iterator operator--(int)
  219. {
  220. default_init_construct_iterator result (*this);
  221. decrement();
  222. return result;
  223. }
  224. friend bool operator== (const default_init_construct_iterator& i, const default_init_construct_iterator& i2)
  225. { return i.equal(i2); }
  226. friend bool operator!= (const default_init_construct_iterator& i, const default_init_construct_iterator& i2)
  227. { return !(i == i2); }
  228. friend bool operator< (const default_init_construct_iterator& i, const default_init_construct_iterator& i2)
  229. { return i.less(i2); }
  230. friend bool operator> (const default_init_construct_iterator& i, const default_init_construct_iterator& i2)
  231. { return i2 < i; }
  232. friend bool operator<= (const default_init_construct_iterator& i, const default_init_construct_iterator& i2)
  233. { return !(i > i2); }
  234. friend bool operator>= (const default_init_construct_iterator& i, const default_init_construct_iterator& i2)
  235. { return !(i < i2); }
  236. friend Difference operator- (const default_init_construct_iterator& i, const default_init_construct_iterator& i2)
  237. { return i2.distance_to(i); }
  238. //Arithmetic
  239. default_init_construct_iterator& operator+=(Difference off)
  240. { this->advance(off); return *this; }
  241. default_init_construct_iterator operator+(Difference off) const
  242. {
  243. default_init_construct_iterator other(*this);
  244. other.advance(off);
  245. return other;
  246. }
  247. friend default_init_construct_iterator operator+(Difference off, const default_init_construct_iterator& right)
  248. { return right + off; }
  249. default_init_construct_iterator& operator-=(Difference off)
  250. { this->advance(-off); return *this; }
  251. default_init_construct_iterator operator-(Difference off) const
  252. { return *this + (-off); }
  253. //This pseudo-iterator's dereference operations have no sense since value is not
  254. //constructed until ::boost::container::construct_in_place is called.
  255. //So comment them to catch bad uses
  256. //const T& operator*() const;
  257. //const T& operator[](difference_type) const;
  258. //const T* operator->() const;
  259. private:
  260. Difference m_num;
  261. void increment()
  262. { --m_num; }
  263. void decrement()
  264. { ++m_num; }
  265. bool equal(const this_type &other) const
  266. { return m_num == other.m_num; }
  267. bool less(const this_type &other) const
  268. { return other.m_num < m_num; }
  269. const T & dereference() const
  270. {
  271. static T dummy;
  272. return dummy;
  273. }
  274. void advance(Difference n)
  275. { m_num -= n; }
  276. Difference distance_to(const this_type &other)const
  277. { return m_num - other.m_num; }
  278. };
  279. template <class T, class Difference = std::ptrdiff_t>
  280. class repeat_iterator
  281. : public std::iterator
  282. <std::random_access_iterator_tag, T, Difference>
  283. {
  284. typedef repeat_iterator<T, Difference> this_type;
  285. public:
  286. explicit repeat_iterator(T &ref, Difference range_size)
  287. : m_ptr(&ref), m_num(range_size){}
  288. //Constructors
  289. repeat_iterator()
  290. : m_ptr(0), m_num(0){}
  291. this_type& operator++()
  292. { increment(); return *this; }
  293. this_type operator++(int)
  294. {
  295. this_type result (*this);
  296. increment();
  297. return result;
  298. }
  299. this_type& operator--()
  300. { increment(); return *this; }
  301. this_type operator--(int)
  302. {
  303. this_type result (*this);
  304. increment();
  305. return result;
  306. }
  307. friend bool operator== (const this_type& i, const this_type& i2)
  308. { return i.equal(i2); }
  309. friend bool operator!= (const this_type& i, const this_type& i2)
  310. { return !(i == i2); }
  311. friend bool operator< (const this_type& i, const this_type& i2)
  312. { return i.less(i2); }
  313. friend bool operator> (const this_type& i, const this_type& i2)
  314. { return i2 < i; }
  315. friend bool operator<= (const this_type& i, const this_type& i2)
  316. { return !(i > i2); }
  317. friend bool operator>= (const this_type& i, const this_type& i2)
  318. { return !(i < i2); }
  319. friend Difference operator- (const this_type& i, const this_type& i2)
  320. { return i2.distance_to(i); }
  321. //Arithmetic
  322. this_type& operator+=(Difference off)
  323. { this->advance(off); return *this; }
  324. this_type operator+(Difference off) const
  325. {
  326. this_type other(*this);
  327. other.advance(off);
  328. return other;
  329. }
  330. friend this_type operator+(Difference off, const this_type& right)
  331. { return right + off; }
  332. this_type& operator-=(Difference off)
  333. { this->advance(-off); return *this; }
  334. this_type operator-(Difference off) const
  335. { return *this + (-off); }
  336. T& operator*() const
  337. { return dereference(); }
  338. T& operator[] (Difference ) const
  339. { return dereference(); }
  340. T *operator->() const
  341. { return &(dereference()); }
  342. private:
  343. T * m_ptr;
  344. Difference m_num;
  345. void increment()
  346. { --m_num; }
  347. void decrement()
  348. { ++m_num; }
  349. bool equal(const this_type &other) const
  350. { return m_num == other.m_num; }
  351. bool less(const this_type &other) const
  352. { return other.m_num < m_num; }
  353. T & dereference() const
  354. { return *m_ptr; }
  355. void advance(Difference n)
  356. { m_num -= n; }
  357. Difference distance_to(const this_type &other)const
  358. { return m_num - other.m_num; }
  359. };
  360. template <class T, class EmplaceFunctor, class Difference /*= std::ptrdiff_t*/>
  361. class emplace_iterator
  362. : public std::iterator
  363. <std::random_access_iterator_tag, T, Difference, const T*, const T &>
  364. {
  365. typedef emplace_iterator this_type;
  366. public:
  367. typedef Difference difference_type;
  368. explicit emplace_iterator(EmplaceFunctor&e)
  369. : m_num(1), m_pe(&e){}
  370. emplace_iterator()
  371. : m_num(0), m_pe(0){}
  372. this_type& operator++()
  373. { increment(); return *this; }
  374. this_type operator++(int)
  375. {
  376. this_type result (*this);
  377. increment();
  378. return result;
  379. }
  380. this_type& operator--()
  381. { decrement(); return *this; }
  382. this_type operator--(int)
  383. {
  384. this_type result (*this);
  385. decrement();
  386. return result;
  387. }
  388. friend bool operator== (const this_type& i, const this_type& i2)
  389. { return i.equal(i2); }
  390. friend bool operator!= (const this_type& i, const this_type& i2)
  391. { return !(i == i2); }
  392. friend bool operator< (const this_type& i, const this_type& i2)
  393. { return i.less(i2); }
  394. friend bool operator> (const this_type& i, const this_type& i2)
  395. { return i2 < i; }
  396. friend bool operator<= (const this_type& i, const this_type& i2)
  397. { return !(i > i2); }
  398. friend bool operator>= (const this_type& i, const this_type& i2)
  399. { return !(i < i2); }
  400. friend difference_type operator- (const this_type& i, const this_type& i2)
  401. { return i2.distance_to(i); }
  402. //Arithmetic
  403. this_type& operator+=(difference_type off)
  404. { this->advance(off); return *this; }
  405. this_type operator+(difference_type off) const
  406. {
  407. this_type other(*this);
  408. other.advance(off);
  409. return other;
  410. }
  411. friend this_type operator+(difference_type off, const this_type& right)
  412. { return right + off; }
  413. this_type& operator-=(difference_type off)
  414. { this->advance(-off); return *this; }
  415. this_type operator-(difference_type off) const
  416. { return *this + (-off); }
  417. //This pseudo-iterator's dereference operations have no sense since value is not
  418. //constructed until ::boost::container::construct_in_place is called.
  419. //So comment them to catch bad uses
  420. //const T& operator*() const;
  421. //const T& operator[](difference_type) const;
  422. //const T* operator->() const;
  423. template<class A>
  424. void construct_in_place(A &a, T* ptr)
  425. { (*m_pe)(a, ptr); }
  426. private:
  427. difference_type m_num;
  428. EmplaceFunctor * m_pe;
  429. void increment()
  430. { --m_num; }
  431. void decrement()
  432. { ++m_num; }
  433. bool equal(const this_type &other) const
  434. { return m_num == other.m_num; }
  435. bool less(const this_type &other) const
  436. { return other.m_num < m_num; }
  437. const T & dereference() const
  438. {
  439. static T dummy;
  440. return dummy;
  441. }
  442. void advance(difference_type n)
  443. { m_num -= n; }
  444. difference_type distance_to(const this_type &other)const
  445. { return difference_type(m_num - other.m_num); }
  446. };
  447. #ifdef BOOST_CONTAINER_PERFECT_FORWARDING
  448. template<class ...Args>
  449. struct emplace_functor
  450. {
  451. typedef typename container_detail::build_number_seq<sizeof...(Args)>::type index_tuple_t;
  452. emplace_functor(Args&&... args)
  453. : args_(args...)
  454. {}
  455. template<class A, class T>
  456. void operator()(A &a, T *ptr)
  457. { emplace_functor::inplace_impl(a, ptr, index_tuple_t()); }
  458. template<class A, class T, int ...IdxPack>
  459. void inplace_impl(A &a, T* ptr, const container_detail::index_tuple<IdxPack...>&)
  460. {
  461. allocator_traits<A>::construct
  462. (a, ptr, ::boost::forward<Args>(container_detail::get<IdxPack>(args_))...);
  463. }
  464. container_detail::tuple<Args&...> args_;
  465. };
  466. #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
  467. #define BOOST_PP_LOCAL_MACRO(n) \
  468. BOOST_PP_EXPR_IF(n, template <) \
  469. BOOST_PP_ENUM_PARAMS(n, class P) \
  470. BOOST_PP_EXPR_IF(n, >) \
  471. struct BOOST_PP_CAT(BOOST_PP_CAT(emplace_functor, n), arg) \
  472. { \
  473. BOOST_PP_CAT(BOOST_PP_CAT(emplace_functor, n), arg) \
  474. ( BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _) ) \
  475. BOOST_PP_EXPR_IF(n, :) BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_INIT, _){} \
  476. \
  477. template<class A, class T> \
  478. void operator()(A &a, T *ptr) \
  479. { \
  480. allocator_traits<A>::construct \
  481. (a, ptr BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_MEMBER_FORWARD, _) ); \
  482. } \
  483. BOOST_PP_REPEAT(n, BOOST_CONTAINER_PP_PARAM_DEFINE, _) \
  484. }; \
  485. //!
  486. #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
  487. #include BOOST_PP_LOCAL_ITERATE()
  488. #endif
  489. namespace container_detail {
  490. template<class T>
  491. struct has_iterator_category
  492. {
  493. template <typename X>
  494. static char test(int, typename X::iterator_category*);
  495. template <typename X>
  496. static int test(int, ...);
  497. static const bool value = (1 == sizeof(test<T>(0, 0)));
  498. };
  499. template<class T, bool = has_iterator_category<T>::value >
  500. struct is_input_iterator
  501. {
  502. static const bool value = is_same<typename T::iterator_category, std::input_iterator_tag>::value;
  503. };
  504. template<class T>
  505. struct is_input_iterator<T, false>
  506. {
  507. static const bool value = false;
  508. };
  509. template<class T, bool = has_iterator_category<T>::value >
  510. struct is_forward_iterator
  511. {
  512. static const bool value = is_same<typename T::iterator_category, std::forward_iterator_tag>::value;
  513. };
  514. template<class T>
  515. struct is_forward_iterator<T, false>
  516. {
  517. static const bool value = false;
  518. };
  519. template<class T, bool = has_iterator_category<T>::value >
  520. struct is_bidirectional_iterator
  521. {
  522. static const bool value = is_same<typename T::iterator_category, std::bidirectional_iterator_tag>::value;
  523. };
  524. template<class T>
  525. struct is_bidirectional_iterator<T, false>
  526. {
  527. static const bool value = false;
  528. };
  529. template<class IIterator>
  530. struct iiterator_types
  531. {
  532. typedef typename IIterator::value_type it_value_type;
  533. typedef typename it_value_type::value_type value_type;
  534. typedef typename std::iterator_traits<IIterator>::pointer it_pointer;
  535. typedef typename std::iterator_traits<IIterator>::difference_type difference_type;
  536. typedef typename ::boost::intrusive::pointer_traits<it_pointer>::
  537. template rebind_pointer<value_type>::type pointer;
  538. typedef typename ::boost::intrusive::pointer_traits<it_pointer>::
  539. template rebind_pointer<const value_type>::type const_pointer;
  540. typedef typename ::boost::intrusive::
  541. pointer_traits<pointer>::reference reference;
  542. typedef typename ::boost::intrusive::
  543. pointer_traits<const_pointer>::reference const_reference;
  544. typedef typename IIterator::iterator_category iterator_category;
  545. };
  546. template<class IIterator, bool IsConst>
  547. struct std_iterator
  548. {
  549. typedef typename std::iterator
  550. < typename iiterator_types<IIterator>::iterator_category
  551. , typename iiterator_types<IIterator>::value_type
  552. , typename iiterator_types<IIterator>::difference_type
  553. , typename iiterator_types<IIterator>::const_pointer
  554. , typename iiterator_types<IIterator>::const_reference> type;
  555. };
  556. template<class IIterator>
  557. struct std_iterator<IIterator, false>
  558. {
  559. typedef typename std::iterator
  560. < typename iiterator_types<IIterator>::iterator_category
  561. , typename iiterator_types<IIterator>::value_type
  562. , typename iiterator_types<IIterator>::difference_type
  563. , typename iiterator_types<IIterator>::pointer
  564. , typename iiterator_types<IIterator>::reference> type;
  565. };
  566. template<class IIterator, bool IsConst>
  567. class iterator
  568. : public std_iterator<IIterator, IsConst>::type
  569. {
  570. typedef typename std_iterator<IIterator, IsConst>::type types_t;
  571. public:
  572. typedef typename types_t::value_type value_type;
  573. typedef typename types_t::pointer pointer;
  574. typedef typename types_t::reference reference;
  575. iterator()
  576. {}
  577. explicit iterator(IIterator iit) BOOST_CONTAINER_NOEXCEPT
  578. : m_iit(iit)
  579. {}
  580. iterator(iterator<IIterator, false> const& other) BOOST_CONTAINER_NOEXCEPT
  581. : m_iit(other.get())
  582. {}
  583. iterator& operator++() BOOST_CONTAINER_NOEXCEPT
  584. { ++this->m_iit; return *this; }
  585. iterator operator++(int) BOOST_CONTAINER_NOEXCEPT
  586. {
  587. iterator result (*this);
  588. ++this->m_iit;
  589. return result;
  590. }
  591. iterator& operator--() BOOST_CONTAINER_NOEXCEPT
  592. {
  593. //If the iterator is not a bidirectional iterator, operator-- should not exist
  594. BOOST_STATIC_ASSERT((is_bidirectional_iterator<iterator>::value));
  595. --this->m_iit; return *this;
  596. }
  597. iterator operator--(int) BOOST_CONTAINER_NOEXCEPT
  598. {
  599. iterator result (*this);
  600. --this->m_iit;
  601. return result;
  602. }
  603. friend bool operator== (const iterator& l, const iterator& r) BOOST_CONTAINER_NOEXCEPT
  604. { return l.m_iit == r.m_iit; }
  605. friend bool operator!= (const iterator& l, const iterator& r) BOOST_CONTAINER_NOEXCEPT
  606. { return !(l == r); }
  607. reference operator*() const BOOST_CONTAINER_NOEXCEPT
  608. { return (*this->m_iit).get_data(); }
  609. pointer operator->() const BOOST_CONTAINER_NOEXCEPT
  610. { return ::boost::intrusive::pointer_traits<pointer>::pointer_to(this->operator*()); }
  611. const IIterator &get() const BOOST_CONTAINER_NOEXCEPT
  612. { return this->m_iit; }
  613. private:
  614. IIterator m_iit;
  615. };
  616. } //namespace container_detail {
  617. } //namespace container {
  618. } //namespace boost {
  619. #include <boost/container/detail/config_end.hpp>
  620. #endif //#ifndef BOOST_CONTAINER_DETAIL_ITERATORS_HPP