map.hpp 4.0 KB

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