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 #include <boost/fusion/support/void.hpp>
39 #include <boost/fusion/support/detail/enabler.hpp>
40 
41 #include <boost/utility/enable_if.hpp>
42 
43 namespace boost { namespace fusion
44 {
45     struct map_tag;
46 
47     template <typename ...T>
48     struct map : detail::map_impl<0, T...>, sequence_base<map<T...>>
49     {
50         typedef map_tag fusion_tag;
51         typedef detail::map_impl<0, T...> base_type;
52 
53         struct category : random_access_traversal_tag, associative_tag {};
54         typedef mpl::int_<base_type::size> size;
55         typedef mpl::false_ is_view;
56 
57         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map58         map() {}
59 
60         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map61         map(map const& seq)
62           : base_type(seq.base())
63         {}
64 
65         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map66         map(map&& seq)
67           : base_type(std::forward<map>(seq))
68         {}
69 
70         template <typename Sequence, typename = typename enable_if<traits::is_sequence<Sequence>>::type>
71         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map72         map(Sequence const& seq)
73           : base_type(begin(seq), detail::map_impl_from_iterator())
74         {}
75 
76         template <typename Sequence, typename = typename enable_if<traits::is_sequence<Sequence>>::type>
77         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map78         map(Sequence& seq)
79           : base_type(begin(seq), detail::map_impl_from_iterator())
80         {}
81 
82         template <typename Sequence, typename = typename enable_if<traits::is_sequence<Sequence>>::type>
83         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map84         map(Sequence&& seq)
85           : base_type(begin(seq), detail::map_impl_from_iterator())
86         {}
87 
88         template <typename First, typename ...T_>
89         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map90         map(First const& first, T_ const&... rest)
91           : base_type(first, rest...)
92         {}
93 
94         template <typename First, typename ...T_>
95         BOOST_FUSION_GPU_ENABLED
mapboost::fusion::map96         map(First&& first, T_&&... rest)
97           : base_type(BOOST_FUSION_FWD_ELEM(First, first), BOOST_FUSION_FWD_ELEM(T_, rest)...)
98         {}
99 
100         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
operator =boost::fusion::map101         map& operator=(map const& rhs)
102         {
103             base_type::operator=(rhs.base());
104             return *this;
105         }
106 
107         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
operator =boost::fusion::map108         map& operator=(map&& rhs)
109         {
110             base_type::operator=(std::forward<base_type>(rhs.base()));
111             return *this;
112         }
113 
114         template <typename Sequence>
115         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
116         typename enable_if<traits::is_sequence<Sequence>, map&>::type
operator =boost::fusion::map117         operator=(Sequence const& seq)
118         {
119             base().assign(begin(seq), detail::map_impl_from_iterator());
120             return *this;
121         }
122 
123         BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
baseboost::fusion::map124         base_type& base() BOOST_NOEXCEPT { return *this; }
125         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
baseboost::fusion::map126         base_type const& base() const BOOST_NOEXCEPT { return *this; }
127     };
128 }}
129 
130 #endif
131 #endif
132