pair_view.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #ifndef BOOST_MPL_PAIR_VIEW_HPP_INCLUDED
  2. #define BOOST_MPL_PAIR_VIEW_HPP_INCLUDED
  3. // Copyright David Abrahams 2003-2004
  4. // Copyright Aleksey Gurtovoy 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/begin_end.hpp>
  15. #include <boost/mpl/iterator_category.hpp>
  16. #include <boost/mpl/advance.hpp>
  17. #include <boost/mpl/distance.hpp>
  18. #include <boost/mpl/next_prior.hpp>
  19. #include <boost/mpl/deref.hpp>
  20. #include <boost/mpl/min_max.hpp>
  21. #include <boost/mpl/pair.hpp>
  22. #include <boost/mpl/iterator_tags.hpp>
  23. #include <boost/mpl/aux_/config/ctps.hpp>
  24. #include <boost/mpl/aux_/na_spec.hpp>
  25. namespace boost { namespace mpl {
  26. namespace aux {
  27. struct pair_iter_tag;
  28. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  29. template< typename Iter1, typename Iter2, typename Category >
  30. struct pair_iter;
  31. template< typename Category > struct prior_pair_iter
  32. {
  33. template< typename Iter1, typename Iter2 > struct apply
  34. {
  35. typedef typename mpl::prior<Iter1>::type i1_;
  36. typedef typename mpl::prior<Iter2>::type i2_;
  37. typedef pair_iter<i1_,i2_,Category> type;
  38. };
  39. };
  40. template<> struct prior_pair_iter<forward_iterator_tag>
  41. {
  42. template< typename Iter1, typename Iter2 > struct apply
  43. {
  44. typedef pair_iter<Iter1,Iter2,forward_iterator_tag> type;
  45. };
  46. };
  47. #endif
  48. }
  49. template<
  50. typename Iter1
  51. , typename Iter2
  52. , typename Category
  53. >
  54. struct pair_iter
  55. {
  56. typedef aux::pair_iter_tag tag;
  57. typedef Category category;
  58. typedef Iter1 first;
  59. typedef Iter2 second;
  60. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  61. typedef pair<
  62. typename deref<Iter1>::type
  63. , typename deref<Iter2>::type
  64. > type;
  65. typedef typename mpl::next<Iter1>::type i1_;
  66. typedef typename mpl::next<Iter2>::type i2_;
  67. typedef pair_iter<i1_,i2_,Category> next;
  68. typedef apply_wrap2< aux::prior_pair_iter<Category>,Iter1,Iter2 >::type prior;
  69. #endif
  70. };
  71. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  72. template< typename Iter1, typename Iter2, typename C >
  73. struct deref< pair_iter<Iter1,Iter2,C> >
  74. {
  75. typedef pair<
  76. typename deref<Iter1>::type
  77. , typename deref<Iter2>::type
  78. > type;
  79. };
  80. template< typename Iter1, typename Iter2, typename C >
  81. struct next< pair_iter<Iter1,Iter2,C> >
  82. {
  83. typedef typename mpl::next<Iter1>::type i1_;
  84. typedef typename mpl::next<Iter2>::type i2_;
  85. typedef pair_iter<i1_,i2_,C> type;
  86. };
  87. template< typename Iter1, typename Iter2, typename C >
  88. struct prior< pair_iter<Iter1,Iter2,C> >
  89. {
  90. typedef typename mpl::prior<Iter1>::type i1_;
  91. typedef typename mpl::prior<Iter2>::type i2_;
  92. typedef pair_iter<i1_,i2_,C> type;
  93. };
  94. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  95. template<> struct advance_impl<aux::pair_iter_tag>
  96. {
  97. template< typename Iter, typename D > struct apply
  98. {
  99. typedef typename mpl::advance< typename Iter::first,D >::type i1_;
  100. typedef typename mpl::advance< typename Iter::second,D >::type i2_;
  101. typedef pair_iter<i1_,i2_,typename Iter::category> type;
  102. };
  103. };
  104. template<> struct distance_impl<aux::pair_iter_tag>
  105. {
  106. template< typename Iter1, typename Iter2 > struct apply
  107. {
  108. // agurt, 10/nov/04: MSVC 6.5 ICE-s on forwarding
  109. typedef typename mpl::distance<
  110. typename first<Iter1>::type
  111. , typename first<Iter2>::type
  112. >::type type;
  113. };
  114. };
  115. template<
  116. typename BOOST_MPL_AUX_NA_PARAM(Sequence1)
  117. , typename BOOST_MPL_AUX_NA_PARAM(Sequence2)
  118. >
  119. struct pair_view
  120. {
  121. typedef nested_begin_end_tag tag;
  122. typedef typename begin<Sequence1>::type iter1_;
  123. typedef typename begin<Sequence2>::type iter2_;
  124. typedef typename min<
  125. typename iterator_category<iter1_>::type
  126. , typename iterator_category<iter2_>::type
  127. >::type category_;
  128. typedef pair_iter<iter1_,iter2_,category_> begin;
  129. typedef pair_iter<
  130. typename end<Sequence1>::type
  131. , typename end<Sequence2>::type
  132. , category_
  133. > end;
  134. };
  135. BOOST_MPL_AUX_NA_SPEC(2, pair_view)
  136. }}
  137. #endif // BOOST_MPL_PAIR_VIEW_HPP_INCLUDED