map_impl.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*=============================================================================
  2. Copyright (c) 2005-2013 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_FUSION_MAP_IMPL_02032013_2233)
  7. #define BOOST_FUSION_MAP_IMPL_02032013_2233
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/detail/access.hpp>
  10. #include <boost/fusion/iterator/deref.hpp>
  11. #include <boost/fusion/iterator/next.hpp>
  12. #include <boost/mpl/int.hpp>
  13. #include <boost/mpl/identity.hpp>
  14. namespace boost { namespace fusion
  15. {
  16. struct fusion_sequence_tag;
  17. }}
  18. namespace boost { namespace fusion { namespace detail
  19. {
  20. struct map_impl_from_iterator {};
  21. template <int index, typename ...T>
  22. struct map_impl;
  23. template <int index_>
  24. struct map_impl<index_>
  25. {
  26. typedef fusion_sequence_tag tag;
  27. static int const index = index_;
  28. static int const size = 0;
  29. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  30. map_impl() BOOST_NOEXCEPT {}
  31. template <typename Iterator>
  32. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  33. map_impl(Iterator const&, map_impl_from_iterator) BOOST_NOEXCEPT
  34. {}
  35. template <typename Iterator>
  36. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  37. void assign(Iterator const&, map_impl_from_iterator) BOOST_NOEXCEPT
  38. {}
  39. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  40. void get();
  41. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  42. void get_val();
  43. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  44. void get_key();
  45. };
  46. template <int index_, typename Pair, typename ...T>
  47. struct map_impl<index_, Pair, T...> : map_impl<index_ + 1, T...>
  48. {
  49. typedef fusion_sequence_tag tag;
  50. typedef map_impl<index_+1, T...> rest_type;
  51. using rest_type::get;
  52. using rest_type::get_val;
  53. using rest_type::get_key;
  54. static int const index = index_;
  55. static int const size = rest_type::size + 1;
  56. typedef Pair pair_type;
  57. typedef typename Pair::first_type key_type;
  58. typedef typename Pair::second_type value_type;
  59. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  60. map_impl()
  61. : rest_type(), element()
  62. {}
  63. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  64. map_impl(map_impl const& rhs)
  65. : rest_type(rhs.get_base()), element(rhs.element)
  66. {}
  67. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  68. map_impl(map_impl&& rhs)
  69. : rest_type(BOOST_FUSION_FWD_ELEM(rest_type, *static_cast<rest_type*>(&rhs)))
  70. , element(BOOST_FUSION_FWD_ELEM(Pair, rhs.element))
  71. {}
  72. template <typename ...U>
  73. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  74. map_impl(map_impl<index, U...> const& rhs)
  75. : rest_type(rhs.get_base()), element(rhs.element)
  76. {}
  77. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  78. map_impl(typename detail::call_param<Pair>::type element_
  79. , typename detail::call_param<T>::type... rest)
  80. : rest_type(rest...), element(element_)
  81. {}
  82. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  83. map_impl(Pair&& element_, T&&... rest)
  84. : rest_type(BOOST_FUSION_FWD_ELEM(T, rest)...)
  85. , element(BOOST_FUSION_FWD_ELEM(Pair, element_))
  86. {}
  87. template <typename Iterator>
  88. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  89. map_impl(Iterator const& iter, map_impl_from_iterator fi)
  90. : rest_type(fusion::next(iter), fi)
  91. , element(*iter)
  92. {}
  93. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  94. rest_type& get_base()
  95. {
  96. return *this;
  97. }
  98. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  99. rest_type const& get_base() const
  100. {
  101. return *this;
  102. }
  103. BOOST_FUSION_GPU_ENABLED
  104. mpl::identity<value_type> get_val(mpl::identity<key_type>) const;
  105. BOOST_FUSION_GPU_ENABLED
  106. pair_type get_val(mpl::int_<index>) const;
  107. BOOST_FUSION_GPU_ENABLED
  108. mpl::identity<key_type> get_key(mpl::int_<index>);
  109. BOOST_FUSION_GPU_ENABLED
  110. mpl::identity<key_type> get_key(mpl::int_<index>) const;
  111. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  112. typename cref_result<value_type>::type
  113. get(mpl::identity<key_type>) const
  114. {
  115. return element.second;
  116. }
  117. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  118. typename ref_result<value_type>::type
  119. get(mpl::identity<key_type>)
  120. {
  121. return element.second;
  122. }
  123. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  124. typename cref_result<pair_type>::type
  125. get(mpl::int_<index>) const
  126. {
  127. return element;
  128. }
  129. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  130. typename ref_result<pair_type>::type
  131. get(mpl::int_<index>)
  132. {
  133. return element;
  134. }
  135. template <typename ...U>
  136. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  137. map_impl& operator=(map_impl<index, U...> const& rhs)
  138. {
  139. rest_type::operator=(rhs);
  140. element = rhs.element;
  141. return *this;
  142. }
  143. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  144. map_impl& operator=(map_impl const& rhs)
  145. {
  146. rest_type::operator=(rhs);
  147. element = rhs.element;
  148. return *this;
  149. }
  150. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  151. map_impl& operator=(map_impl&& rhs)
  152. {
  153. rest_type::operator=(std::forward<map_impl>(rhs));
  154. element = BOOST_FUSION_FWD_ELEM(Pair, rhs.element);
  155. return *this;
  156. }
  157. template <typename Iterator>
  158. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  159. void assign(Iterator const& iter, map_impl_from_iterator fi)
  160. {
  161. rest_type::assign(fusion::next(iter), fi);
  162. element = *iter;
  163. }
  164. Pair element;
  165. };
  166. }}}
  167. #endif