Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / fusion / container / map / detail / build_map.hpp
1 /*=============================================================================
2     Copyright (c) 2005-2013 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(BOOST_FUSION_BUILD_MAP_02042013_1448)
8 #define BOOST_FUSION_BUILD_MAP_02042013_1448
9
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/fusion/iterator/equal_to.hpp>
12 #include <boost/fusion/iterator/next.hpp>
13 #include <boost/fusion/iterator/value_of.hpp>
14 #include <boost/fusion/iterator/deref.hpp>
15 #include <boost/fusion/sequence/intrinsic/begin.hpp>
16 #include <boost/fusion/sequence/intrinsic/end.hpp>
17 #include <boost/fusion/container/map/map.hpp>
18 #include <boost/fusion/algorithm/transformation/push_front.hpp>
19
20 namespace boost { namespace fusion { namespace detail
21 {
22     template <typename First, typename Last, bool is_assoc
23       , bool is_empty = result_of::equal_to<First, Last>::value
24     >
25     struct build_map;
26
27     template <typename First, typename Last, bool is_assoc>
28     struct build_map<First, Last, is_assoc, true>
29     {
30         typedef map<> type;
31         BOOST_FUSION_GPU_ENABLED
32         static type
33         call(First const&, Last const&)
34         {
35             return type();
36         }
37     };
38
39     template <typename T, typename Rest>
40     struct push_front_map;
41
42     template <typename T, typename ...Rest>
43     struct push_front_map<T, map<Rest...>>
44     {
45         typedef map<T, Rest...> type;
46
47         BOOST_FUSION_GPU_ENABLED
48         static type
49         call(T const& first, map<Rest...> const& rest)
50         {
51             return type(push_front(rest, first));
52         }
53     };
54
55     template <typename First, typename Last, bool is_assoc>
56     struct build_map<First, Last, is_assoc, false>
57     {
58         typedef
59             build_map<typename result_of::next<First>::type, Last, is_assoc>
60         next_build_map;
61
62         typedef push_front_map<
63             typename pair_from<First, is_assoc>::type
64           , typename next_build_map::type>
65         push_front;
66
67         typedef typename push_front::type type;
68
69         BOOST_FUSION_GPU_ENABLED
70         static type
71         call(First const& f, Last const& l)
72         {
73             return push_front::call(
74                 pair_from<First, is_assoc>::call(f)
75               , next_build_map::call(fusion::next(f), l));
76         }
77     };
78 }}}
79
80 #endif