transform_iter.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef BOOST_MPL_AUX_TRANSFORM_ITER_HPP_INCLUDED
  2. #define BOOST_MPL_AUX_TRANSFORM_ITER_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/apply.hpp>
  14. #include <boost/mpl/iterator_tags.hpp>
  15. #include <boost/mpl/next.hpp>
  16. #include <boost/mpl/deref.hpp>
  17. #include <boost/mpl/aux_/lambda_spec.hpp>
  18. #include <boost/mpl/aux_/config/ctps.hpp>
  19. #include <boost/type_traits/is_same.hpp>
  20. namespace boost { namespace mpl {
  21. namespace aux {
  22. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  23. template<
  24. typename Iterator
  25. , typename LastIterator
  26. , typename F
  27. >
  28. struct transform_iter
  29. {
  30. typedef Iterator base;
  31. typedef forward_iterator_tag category;
  32. typedef transform_iter< typename mpl::next<base>::type,LastIterator,F > next;
  33. typedef typename apply1<
  34. F
  35. , typename deref<base>::type
  36. >::type type;
  37. };
  38. template<
  39. typename LastIterator
  40. , typename F
  41. >
  42. struct transform_iter< LastIterator,LastIterator,F >
  43. {
  44. typedef LastIterator base;
  45. typedef forward_iterator_tag category;
  46. };
  47. #else
  48. template<
  49. typename Iterator
  50. , typename LastIterator
  51. , typename F
  52. >
  53. struct transform_iter;
  54. template< bool >
  55. struct transform_iter_impl
  56. {
  57. template<
  58. typename Iterator
  59. , typename LastIterator
  60. , typename F
  61. >
  62. struct result_
  63. {
  64. typedef Iterator base;
  65. typedef forward_iterator_tag category;
  66. typedef transform_iter< typename mpl::next<Iterator>::type,LastIterator,F > next;
  67. typedef typename apply1<
  68. F
  69. , typename deref<Iterator>::type
  70. >::type type;
  71. };
  72. };
  73. template<>
  74. struct transform_iter_impl<true>
  75. {
  76. template<
  77. typename Iterator
  78. , typename LastIterator
  79. , typename F
  80. >
  81. struct result_
  82. {
  83. typedef Iterator base;
  84. typedef forward_iterator_tag category;
  85. };
  86. };
  87. template<
  88. typename Iterator
  89. , typename LastIterator
  90. , typename F
  91. >
  92. struct transform_iter
  93. : transform_iter_impl<
  94. ::boost::is_same<Iterator,LastIterator>::value
  95. >::template result_< Iterator,LastIterator,F >
  96. {
  97. };
  98. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  99. } // namespace aux
  100. BOOST_MPL_AUX_PASS_THROUGH_LAMBDA_SPEC(3, aux::transform_iter)
  101. }}
  102. #endif // BOOST_MPL_AUX_TRANSFORM_ITER_HPP_INCLUDED