Ticket #8270: as_map.patch
File as_map.patch, 7.4 KB (added by , 10 years ago) |
---|
-
convert.hpp
9 9 10 10 #include <boost/fusion/container/map/map.hpp> 11 11 12 namespace boost { namespace fusion { namespace detail 13 { 14 template <typename It, bool is_assoc> 15 struct pair_from 16 { 17 typedef typename result_of::value_of<It>::type type; 18 19 static inline type call(It const& it) 20 { 21 return *it; 22 } 23 }; 24 25 template <typename It> 26 struct pair_from<It, true> 27 { 28 typedef typename result_of::key_of<It>::type key_type; 29 typedef typename result_of::value_of_data<It>::type data_type; 30 typedef typename fusion::pair<key_type, data_type> type; 31 32 static inline type call(It const& it) 33 { 34 return type(deref_data(it)); 35 } 36 }; 37 }}} 38 12 39 /////////////////////////////////////////////////////////////////////////////// 13 40 // Without variadics, we will use the PP version 14 41 /////////////////////////////////////////////////////////////////////////////// … … 30 57 detail::build_map< 31 58 typename result_of::begin<Sequence>::type 32 59 , typename result_of::end<Sequence>::type 60 , is_base_of< 61 associative_tag 62 , typename traits::category_of<Sequence>::type>::value 33 63 > 34 64 { 35 65 }; -
detail/build_map.hpp
18 18 19 19 namespace boost { namespace fusion { namespace detail 20 20 { 21 template <typename First, typename Last 22 , bool is_empty = result_of::equal_to<First, Last>::value> 21 template <typename First, typename Last, bool is_assoc 22 , bool is_empty = result_of::equal_to<First, Last>::value 23 > 23 24 struct build_map; 24 25 25 template <typename First, typename Last >26 struct build_map<First, Last, true>26 template <typename First, typename Last, bool is_assoc> 27 struct build_map<First, Last, is_assoc, true> 27 28 { 28 29 typedef map<> type; 29 30 static type … … 48 49 } 49 50 }; 50 51 51 template <typename First, typename Last >52 struct build_map<First, Last, false>52 template <typename First, typename Last, bool is_assoc> 53 struct build_map<First, Last, is_assoc, false> 53 54 { 54 55 typedef 55 build_map<typename result_of::next<First>::type, Last >56 build_map<typename result_of::next<First>::type, Last, is_assoc> 56 57 next_build_map; 57 58 58 59 typedef push_front_map< 59 typename result_of::value_of<First>::type60 typename pair_from<First, is_assoc>::type 60 61 , typename next_build_map::type> 61 62 push_front; 62 63 … … 65 66 static type 66 67 call(First const& f, Last const& l) 67 68 { 68 typename result_of::value_of<First>::type v = *f;69 69 return push_front::call( 70 v, next_build_map::call(fusion::next(f), l)); 70 pair_from<First, is_assoc>::call(f) 71 , next_build_map::call(fusion::next(f), l)); 71 72 } 72 73 }; 73 74 }}} -
detail/cpp03/as_map.hpp
22 22 23 23 namespace boost { namespace fusion { namespace detail 24 24 { 25 template <int size >25 template <int size, bool is_assoc> 26 26 struct as_map; 27 27 28 template < >29 struct as_map<0 >28 template <bool is_assoc> 29 struct as_map<0, is_assoc> 30 30 { 31 31 template <typename Iterator> 32 32 struct apply … … 73 73 typename gen::BOOST_PP_CAT(I, BOOST_PP_INC(n)) \ 74 74 BOOST_PP_CAT(i, BOOST_PP_INC(n)) = fusion::next(BOOST_PP_CAT(i, n)); 75 75 76 #define BOOST_FUSION_ VALUE_OF_ITERATOR(z, n, data)\77 typedef typename fusion::result_of::value_of<BOOST_PP_CAT(I, n)>::type\78 76 #define BOOST_FUSION_PAIR_FROM_ITERATOR(z, n, data) \ 77 typedef pair_from<BOOST_PP_CAT(I, n), is_assoc> BOOST_PP_CAT(D, n); \ 78 typedef typename BOOST_PP_CAT(D, n)::type BOOST_PP_CAT(T, n); 79 79 80 #define BOOST_FUSION_DREF_CALL_ITERATOR(z, n, data) \ 81 gen::BOOST_PP_CAT(D, n)::call(BOOST_PP_CAT(i, n)) 82 80 83 #define BOOST_PP_FILENAME_1 <boost/fusion/container/map/detail/cpp03/as_map.hpp> 81 84 #define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_MAP_SIZE) 82 85 #include BOOST_PP_ITERATE() 83 86 84 87 #undef BOOST_FUSION_NEXT_ITERATOR 85 88 #undef BOOST_FUSION_NEXT_CALL_ITERATOR 86 #undef BOOST_FUSION_VALUE_OF_ITERATOR 89 #undef BOOST_FUSION_PAIR_FROM_ITERATOR 90 #undef BOOST_FUSION_DREF_CALL_ITERATOR 87 91 88 92 }}} 89 93 … … 103 107 104 108 #define N BOOST_PP_ITERATION() 105 109 106 template < >107 struct as_map<N >110 template <bool is_assoc> 111 struct as_map<N, is_assoc> 108 112 { 109 113 template <typename I0> 110 114 struct apply 111 115 { 112 BOOST_PP_REPEAT( N, BOOST_FUSION_NEXT_ITERATOR, _)113 BOOST_PP_REPEAT(N, BOOST_FUSION_ VALUE_OF_ITERATOR, _)116 BOOST_PP_REPEAT(BOOST_PP_DEC(N), BOOST_FUSION_NEXT_ITERATOR, _) 117 BOOST_PP_REPEAT(N, BOOST_FUSION_PAIR_FROM_ITERATOR, _) 114 118 typedef map<BOOST_PP_ENUM_PARAMS(N, T)> type; 115 119 }; 116 120 … … 121 125 typedef apply<Iterator> gen; 122 126 typedef typename gen::type result; 123 127 BOOST_PP_REPEAT(BOOST_PP_DEC(N), BOOST_FUSION_NEXT_CALL_ITERATOR, _) 124 return result(BOOST_PP_ENUM _PARAMS(N, *i));128 return result(BOOST_PP_ENUM(N, BOOST_FUSION_DREF_CALL_ITERATOR, _)); 125 129 } 126 130 }; 127 131 -
detail/cpp03/convert.hpp
20 20 template <typename Sequence> 21 21 struct as_map 22 22 { 23 typedef typename detail::as_map<result_of::size<Sequence>::value> gen; 23 typedef typename 24 detail::as_map< 25 result_of::size<Sequence>::value 26 , is_base_of< 27 associative_tag 28 , typename traits::category_of<Sequence>::type>::value 29 > 30 gen; 24 31 typedef typename gen:: 25 32 template apply<typename result_of::begin<Sequence>::type>::type 26 33 type; -
detail/cpp03/convert_impl.hpp
28 28 template <typename Sequence> 29 29 struct apply 30 30 { 31 typedef typename detail::as_map<result_of::size<Sequence>::value> gen; 31 typedef typename 32 detail::as_map< 33 result_of::size<Sequence>::value 34 , is_base_of< 35 associative_tag 36 , typename traits::category_of<Sequence>::type>::value 37 > 38 gen; 32 39 typedef typename gen:: 33 40 template apply<typename result_of::begin<Sequence>::type>::type 34 41 type;