Ticket #8270: as_map.patch

File as_map.patch, 7.4 KB (added by Jamboree <tongari95@…>, 10 years ago)

source without preprocessed files

  • convert.hpp

     
    99
    1010#include <boost/fusion/container/map/map.hpp>
    1111
     12namespace 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
    1239///////////////////////////////////////////////////////////////////////////////
    1340// Without variadics, we will use the PP version
    1441///////////////////////////////////////////////////////////////////////////////
     
    3057            detail::build_map<
    3158                typename result_of::begin<Sequence>::type
    3259              , typename result_of::end<Sequence>::type
     60              , is_base_of<
     61                    associative_tag
     62                  , typename traits::category_of<Sequence>::type>::value
    3363            >
    3464        {
    3565        };
  • detail/build_map.hpp

     
    1818
    1919namespace boost { namespace fusion { namespace detail
    2020{
    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    >
    2324    struct build_map;
    2425
    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>
    2728    {
    2829        typedef map<> type;
    2930        static type
     
    4849        }
    4950    };
    5051
    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>
    5354    {
    5455        typedef
    55             build_map<typename result_of::next<First>::type, Last>
     56            build_map<typename result_of::next<First>::type, Last, is_assoc>
    5657        next_build_map;
    5758
    5859        typedef push_front_map<
    59             typename result_of::value_of<First>::type
     60            typename pair_from<First, is_assoc>::type
    6061          , typename next_build_map::type>
    6162        push_front;
    6263
     
    6566        static type
    6667        call(First const& f, Last const& l)
    6768        {
    68             typename result_of::value_of<First>::type v = *f;
    6969            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));
    7172        }
    7273    };
    7374}}}
  • detail/cpp03/as_map.hpp

     
    2222
    2323namespace boost { namespace fusion { namespace detail
    2424{
    25     template <int size>
     25    template <int size, bool is_assoc>
    2626    struct as_map;
    2727
    28     template <>
    29     struct as_map<0>
     28    template <bool is_assoc>
     29    struct as_map<0, is_assoc>
    3030    {
    3131        template <typename Iterator>
    3232        struct apply
     
    7373    typename gen::BOOST_PP_CAT(I, BOOST_PP_INC(n))                              \
    7474        BOOST_PP_CAT(i, BOOST_PP_INC(n)) = fusion::next(BOOST_PP_CAT(i, n));
    7575
    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         BOOST_PP_CAT(T, n);
     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);
    7979
     80#define BOOST_FUSION_DREF_CALL_ITERATOR(z, n, data)                             \
     81    gen::BOOST_PP_CAT(D, n)::call(BOOST_PP_CAT(i, n))
     82
    8083#define BOOST_PP_FILENAME_1 <boost/fusion/container/map/detail/cpp03/as_map.hpp>
    8184#define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_MAP_SIZE)
    8285#include BOOST_PP_ITERATE()
    8386
    8487#undef BOOST_FUSION_NEXT_ITERATOR
    8588#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
    8791
    8892}}}
    8993
     
    103107
    104108#define N BOOST_PP_ITERATION()
    105109
    106     template <>
    107     struct as_map<N>
     110    template <bool is_assoc>
     111    struct as_map<N, is_assoc>
    108112    {
    109113        template <typename I0>
    110114        struct apply
    111115        {
    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, _)
    114118            typedef map<BOOST_PP_ENUM_PARAMS(N, T)> type;
    115119        };
    116120
     
    121125            typedef apply<Iterator> gen;
    122126            typedef typename gen::type result;
    123127            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, _));
    125129        }
    126130    };
    127131
  • detail/cpp03/convert.hpp

     
    2020        template <typename Sequence>
    2121        struct as_map
    2222        {
    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;
    2431            typedef typename gen::
    2532                template apply<typename result_of::begin<Sequence>::type>::type
    2633            type;
  • detail/cpp03/convert_impl.hpp

     
    2828            template <typename Sequence>
    2929            struct apply
    3030            {
    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;
    3239                typedef typename gen::
    3340                    template apply<typename result_of::begin<Sequence>::type>::type
    3441                type;