]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_CONVERT_MAIN_09232005_1340) | |
8 | #define FUSION_CONVERT_MAIN_09232005_1340 | |
9 | ||
10 | #include <boost/fusion/support/config.hpp> | |
11 | #include <boost/fusion/container/map/map.hpp> | |
12 | ||
13 | namespace boost { namespace fusion { namespace detail | |
14 | { | |
15 | template <typename It, bool is_assoc> | |
16 | struct pair_from | |
17 | { | |
18 | typedef typename result_of::value_of<It>::type type; | |
19 | ||
20 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
21 | static inline type call(It const& it) | |
22 | { | |
23 | return *it; | |
24 | } | |
25 | }; | |
26 | ||
27 | template <typename It> | |
28 | struct pair_from<It, true> | |
29 | { | |
30 | typedef typename result_of::key_of<It>::type key_type; | |
31 | typedef typename result_of::value_of_data<It>::type data_type; | |
32 | typedef typename fusion::pair<key_type, data_type> type; | |
33 | ||
34 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
35 | static inline type call(It const& it) | |
36 | { | |
37 | return type(deref_data(it)); | |
38 | } | |
39 | }; | |
40 | }}} | |
41 | ||
42 | /////////////////////////////////////////////////////////////////////////////// | |
43 | // Without variadics, we will use the PP version | |
44 | /////////////////////////////////////////////////////////////////////////////// | |
45 | #if !defined(BOOST_FUSION_HAS_VARIADIC_MAP) | |
46 | # include <boost/fusion/container/map/detail/cpp03/convert.hpp> | |
47 | ||
48 | #else | |
49 | /////////////////////////////////////////////////////////////////////////////// | |
50 | // C++11 variadic implementation | |
51 | /////////////////////////////////////////////////////////////////////////////// | |
52 | #include <boost/fusion/container/map/detail/build_map.hpp> | |
53 | ||
54 | namespace boost { namespace fusion | |
55 | { | |
56 | namespace result_of | |
57 | { | |
58 | template <typename Sequence> | |
59 | struct as_map : | |
60 | detail::build_map< | |
61 | typename result_of::begin<Sequence>::type | |
62 | , typename result_of::end<Sequence>::type | |
63 | , is_base_of< | |
64 | associative_tag | |
65 | , typename traits::category_of<Sequence>::type>::value | |
66 | > | |
67 | { | |
68 | }; | |
69 | } | |
70 | ||
71 | template <typename Sequence> | |
72 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
73 | inline typename result_of::as_map<Sequence>::type | |
74 | as_map(Sequence& seq) | |
75 | { | |
76 | typedef result_of::as_map<Sequence> gen; | |
77 | return gen::call(fusion::begin(seq), fusion::end(seq)); | |
78 | } | |
79 | ||
80 | template <typename Sequence> | |
81 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
82 | inline typename result_of::as_map<Sequence const>::type | |
83 | as_map(Sequence const& seq) | |
84 | { | |
85 | typedef result_of::as_map<Sequence const> gen; | |
86 | return gen::call(fusion::begin(seq), fusion::end(seq)); | |
87 | } | |
88 | ||
89 | namespace extension | |
90 | { | |
91 | template <typename T> | |
92 | struct convert_impl; | |
93 | ||
94 | template <> | |
95 | struct convert_impl<map_tag> | |
96 | { | |
97 | template <typename Sequence> | |
98 | struct apply | |
99 | { | |
100 | typedef typename | |
101 | result_of::as_map<Sequence>::type | |
102 | type; | |
103 | ||
104 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
105 | static type call(Sequence& seq) | |
106 | { | |
107 | typedef result_of::as_map<Sequence> gen; | |
108 | return gen::call(fusion::begin(seq), fusion::end(seq)); | |
109 | } | |
110 | }; | |
111 | }; | |
112 | } | |
113 | }} | |
114 | ||
115 | #endif | |
116 | #endif | |
117 |