map.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 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(FUSION_MAP_MAIN_07212005_1106)
  7. #define FUSION_MAP_MAIN_07212005_1106
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/container/map/map_fwd.hpp>
  10. #include <boost/fusion/support/pair.hpp>
  11. ///////////////////////////////////////////////////////////////////////////////
  12. // Without variadics, we will use the PP version
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #if !defined(BOOST_FUSION_HAS_VARIADIC_MAP)
  15. # include <boost/fusion/container/map/detail/cpp03/map.hpp>
  16. #else
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // C++11 interface
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include <boost/fusion/container/map/detail/map_impl.hpp>
  21. #include <boost/fusion/container/map/detail/begin_impl.hpp>
  22. #include <boost/fusion/container/map/detail/end_impl.hpp>
  23. #include <boost/fusion/container/map/detail/at_impl.hpp>
  24. #include <boost/fusion/container/map/detail/at_key_impl.hpp>
  25. #include <boost/fusion/container/map/detail/value_at_impl.hpp>
  26. #include <boost/fusion/container/map/detail/value_at_key_impl.hpp>
  27. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  28. #include <boost/fusion/sequence/intrinsic/end.hpp>
  29. #include <boost/fusion/sequence/intrinsic/at.hpp>
  30. #include <boost/fusion/sequence/intrinsic/at_c.hpp>
  31. #include <boost/fusion/support/is_sequence.hpp>
  32. #include <boost/fusion/support/sequence_base.hpp>
  33. #include <boost/fusion/support/category_of.hpp>
  34. #include <boost/fusion/support/void.hpp>
  35. #include <boost/fusion/support/detail/enabler.hpp>
  36. #include <boost/utility/enable_if.hpp>
  37. namespace boost { namespace fusion
  38. {
  39. struct map_tag;
  40. template <typename ...T>
  41. struct map : detail::map_impl<0, T...>, sequence_base<map<T...>>
  42. {
  43. typedef map_tag fusion_tag;
  44. typedef detail::map_impl<0, T...> base_type;
  45. struct category : random_access_traversal_tag, associative_tag {};
  46. typedef mpl::int_<base_type::size> size;
  47. typedef mpl::false_ is_view;
  48. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  49. map() {}
  50. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  51. map(map const& seq)
  52. : base_type(seq.base())
  53. {}
  54. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  55. map(map&& seq)
  56. : base_type(std::forward<map>(seq))
  57. {}
  58. template <typename Sequence, typename = typename enable_if<traits::is_sequence<Sequence>>::type>
  59. BOOST_FUSION_GPU_ENABLED
  60. map(Sequence const& seq)
  61. : base_type(begin(seq), detail::map_impl_from_iterator())
  62. {}
  63. template <typename Sequence, typename = typename enable_if<traits::is_sequence<Sequence>>::type>
  64. BOOST_FUSION_GPU_ENABLED
  65. map(Sequence& seq)
  66. : base_type(begin(seq), detail::map_impl_from_iterator())
  67. {}
  68. template <typename Sequence, typename = typename enable_if<traits::is_sequence<Sequence>>::type>
  69. BOOST_FUSION_GPU_ENABLED
  70. map(Sequence&& seq)
  71. : base_type(begin(seq), detail::map_impl_from_iterator())
  72. {}
  73. template <typename First, typename ...T_>
  74. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  75. map(First const& first, T_ const&... rest)
  76. : base_type(first, rest...)
  77. {}
  78. template <typename First, typename ...T_>
  79. BOOST_FUSION_GPU_ENABLED
  80. map(First&& first, T_&&... rest)
  81. : base_type(BOOST_FUSION_FWD_ELEM(First, first), BOOST_FUSION_FWD_ELEM(T_, rest)...)
  82. {}
  83. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  84. map& operator=(map const& rhs)
  85. {
  86. base_type::operator=(rhs.base());
  87. return *this;
  88. }
  89. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  90. map& operator=(map&& rhs)
  91. {
  92. base_type::operator=(std::forward<base_type>(rhs.base()));
  93. return *this;
  94. }
  95. template <typename Sequence>
  96. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  97. typename enable_if<traits::is_sequence<Sequence>, map&>::type
  98. operator=(Sequence const& seq)
  99. {
  100. base().assign(begin(seq), detail::map_impl_from_iterator());
  101. return *this;
  102. }
  103. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  104. base_type& base() BOOST_NOEXCEPT { return *this; }
  105. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  106. base_type const& base() const BOOST_NOEXCEPT { return *this; }
  107. };
  108. }}
  109. #endif
  110. #endif