iterator.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #ifndef BOOST_MPL_MAP_AUX_ITERATOR_HPP_INCLUDED
  2. #define BOOST_MPL_MAP_AUX_ITERATOR_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2003-2004
  4. // Copyright David Abrahams 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/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. #include <boost/mpl/map/aux_/map0.hpp>
  15. #include <boost/mpl/map/aux_/at_impl.hpp>
  16. #include <boost/mpl/map/aux_/tag.hpp>
  17. #include <boost/mpl/iterator_tags.hpp>
  18. #include <boost/mpl/if.hpp>
  19. #include <boost/mpl/next.hpp>
  20. #include <boost/mpl/deref.hpp>
  21. #include <boost/mpl/long.hpp>
  22. #include <boost/mpl/void.hpp>
  23. #include <boost/mpl/aux_/nttp_decl.hpp>
  24. #include <boost/mpl/aux_/config/ctps.hpp>
  25. namespace boost { namespace mpl {
  26. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  27. template<
  28. typename Map
  29. , long order
  30. , long max_order
  31. >
  32. struct next_order
  33. : if_<
  34. is_void_< typename item_by_order<Map,order>::type >
  35. , next_order<Map,(order+1),max_order>
  36. , long_<order>
  37. >::type
  38. {
  39. };
  40. template<
  41. typename Map
  42. , long max_order
  43. >
  44. struct next_order<Map,max_order,max_order>
  45. : long_<max_order>
  46. {
  47. };
  48. template< typename Map, long order, long max_order >
  49. struct m_iter
  50. {
  51. typedef forward_iterator_tag category;
  52. typedef typename item_by_order<Map,order>::type type;
  53. };
  54. template< typename Map, long max_order >
  55. struct m_iter<Map,max_order,max_order>
  56. {
  57. typedef forward_iterator_tag category;
  58. };
  59. template< typename Map, long order, long max_order >
  60. struct next< m_iter<Map,order,max_order> >
  61. {
  62. typedef m_iter<
  63. Map
  64. , next_order<Map,order+1,max_order>::value
  65. , max_order
  66. > type;
  67. };
  68. template< typename Map, long max_order >
  69. struct next< m_iter<Map,max_order,max_order> >
  70. {
  71. };
  72. #else
  73. template<
  74. typename Map
  75. , BOOST_MPL_AUX_NTTP_DECL(long, order)
  76. , BOOST_MPL_AUX_NTTP_DECL(long, max_order)
  77. >
  78. struct next_order;
  79. template<
  80. typename Map
  81. , BOOST_MPL_AUX_NTTP_DECL(long, order)
  82. , BOOST_MPL_AUX_NTTP_DECL(long, max_order)
  83. >
  84. struct next_order_impl
  85. : if_<
  86. is_void_< typename item_by_order<Map,order>::type >
  87. , next_order<Map,(order+1),max_order>
  88. , long_<order>
  89. >::type
  90. {
  91. };
  92. template<
  93. typename Map
  94. , BOOST_MPL_AUX_NTTP_DECL(long, order)
  95. , BOOST_MPL_AUX_NTTP_DECL(long, max_order)
  96. >
  97. struct next_order
  98. : if_c<
  99. (order != max_order)
  100. , next_order_impl<Map,order,max_order>
  101. , long_<order>
  102. >::type
  103. {
  104. };
  105. template<
  106. typename Map
  107. , BOOST_MPL_AUX_NTTP_DECL(long, order)
  108. , BOOST_MPL_AUX_NTTP_DECL(long, max_order)
  109. >
  110. struct m_iter;
  111. struct m_iter_empty_base {};
  112. template<
  113. typename Map
  114. , BOOST_MPL_AUX_NTTP_DECL(long, order)
  115. , BOOST_MPL_AUX_NTTP_DECL(long, max_order)
  116. >
  117. struct m_iter_base
  118. {
  119. typedef typename item_by_order<Map,order>::type type;
  120. typedef m_iter<
  121. Map
  122. , next_order<Map,order+1,max_order>::value
  123. , max_order
  124. > next;
  125. };
  126. template<
  127. typename Map
  128. , BOOST_MPL_AUX_NTTP_DECL(long, order)
  129. , BOOST_MPL_AUX_NTTP_DECL(long, max_order)
  130. >
  131. struct m_iter
  132. : if_c<
  133. (order == max_order)
  134. , m_iter_empty_base
  135. , m_iter_base<Map,order,max_order>
  136. >::type
  137. {
  138. typedef forward_iterator_tag category;
  139. };
  140. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  141. }}
  142. #endif // BOOST_MPL_MAP_AUX_ITERATOR_HPP_INCLUDED