1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #if !defined(FUSION_MAP_MAIN_07212005_1106)
8 #define FUSION_MAP_MAIN_07212005_1106
9 
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/fusion/container/map/map_fwd.hpp>
12 #include <boost/fusion/support/pair.hpp>
13 
14 ///////////////////////////////////////////////////////////////////////////////
15 // Without variadics, we will use the PP version
16 ///////////////////////////////////////////////////////////////////////////////
17 #if !defined(BOOST_FUSION_HAS_VARIADIC_MAP)
18 # include <boost/fusion/container/map/detail/cpp03/map.hpp>
19 #else
20 
21 ///////////////////////////////////////////////////////////////////////////////
22 // C++11 interface
23 ///////////////////////////////////////////////////////////////////////////////
24 #include <boost/fusion/container/map/detail/map_impl.hpp>
25 #include <boost/fusion/container/map/detail/begin_impl.hpp>
26 #include <boost/fusion/container/map/detail/end_impl.hpp>
27 #include <boost/fusion/container/map/detail/at_impl.hpp>
28 #include <boost/fusion/container/map/detail/at_key_impl.hpp>
29 #include <boost/fusion/container/map/detail/value_at_impl.hpp>
30 #include <boost/fusion/container/map/detail/value_at_key_impl.hpp>
31 #include <boost/fusion/sequence/intrinsic/begin.hpp>
32 #include <boost/fusion/sequence/intrinsic/end.hpp>
33 #include <boost/fusion/sequence/intrinsic/at.hpp>
34 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
35 #include <boost/fusion/support/is_sequence.hpp>
36 #include <boost/fusion/support/sequence_base.hpp>
37 #include <boost/fusion/support/category_of.hpp>
38 
39 #include <boost/utility/enable_if.hpp>
40 
41 namespace boost { namespace fusion
42 {
43     struct map_tag;
44 
45     template <typename ...T>
46     struct map : detail::map_impl<0, T...>, sequence_base<map<T...>>
47     {
48         typedef map_tag fusion_tag;
49         typedef detail::map_impl<0, T...> base_type;
50 
51         struct category : random_access_traversal_tag, associative_tag {};
52         typedef mpl::int_<base_type::size> size;
53         typedef mpl::false_ is_view;
54 
55         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map56         map() {}
57 
58         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map59         map(map const& seq)
60           : base_type(seq.base())
61         {}
62 
63         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map64         map(map&& seq)
65           : base_type(std::forward<map>(seq))
66         {}
67 
68         template <typename Sequence>
69         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map70         map(Sequence const& seq
71           , typename enable_if<traits::is_sequence<Sequence>>::type* /*dummy*/ = 0)
72           : base_type(begin(seq), detail::map_impl_from_iterator())
73         {}
74 
75         template <typename Sequence>
76         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map77         map(Sequence& seq
78           , typename enable_if<traits::is_sequence<Sequence>>::type* /*dummy*/ = 0)
79           : base_type(begin(seq), detail::map_impl_from_iterator())
80         {}
81 
82         template <typename Sequence>
83         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map84         map(Sequence&& seq
85           , typename enable_if<traits::is_sequence<Sequence>>::type* /*dummy*/ = 0)
86           : base_type(begin(seq), detail::map_impl_from_iterator())
87         {}
88 
89         template <typename First, typename ...T_>
90         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map91         map(First const& first, T_ const&... rest)
92           : base_type(first, rest...)
93         {}
94 
95         template <typename First, typename ...T_>
96         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map97         map(First&& first, T_&&... rest)
98           : base_type(BOOST_FUSION_FWD_ELEM(First, first), BOOST_FUSION_FWD_ELEM(T_, rest)...)
99         {}
100 
101         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
operator =boost::fusion::map102         map& operator=(map const& rhs)
103         {
104             base_type::operator=(rhs.base());
105             return *this;
106         }
107 
108         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
operator =boost::fusion::map109         map& operator=(map&& rhs)
110         {
111             base_type::operator=(std::forward<base_type>(rhs.base()));
112             return *this;
113         }
114 
115         template <typename Sequence>
116         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
117         typename enable_if<traits::is_sequence<Sequence>, map&>::type
operator =boost::fusion::map118         operator=(Sequence const& seq)
119         {
120             base().assign(begin(seq), detail::map_impl_from_iterator());
121             return *this;
122         }
123 
124         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
baseboost::fusion::map125         base_type& base() BOOST_NOEXCEPT { return *this; }
126         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
baseboost::fusion::map127         base_type const& base() const BOOST_NOEXCEPT { return *this; }
128     };
129 }}
130 
131 #endif
132 #endif
133