Find the index of an element in a fusion map
===

I am struggling with a small piece of functionality I'm looking for.

I have a class which contains a `fusion::map`. I would like to use a variadic constructor to initialise the elements in that map.

I expect the easiest way to do this is to construct a `fusion::vector` from the constructor arguments, and then call `for_each` on the map, and setting each pair's value to its corresponding element in the vector.

However, in order to do this I need to calculate the **index** of the pair, based on its key type. (`pair::first_type`)

Can anyone help me?

Please see example code below:

    #include <iostream>
    #include <boost/fusion/container.hpp>
    #include <boost/fusion/sequence.hpp>
    #include <boost/fusion/mpl.hpp>
    #include <boost/fusion/include/has_key.hpp>
    #include <boost/fusion/include/algorithm.hpp>
    #include <boost/mpl/transform.hpp>
    
    namespace fusion = boost::fusion;
    namespace mpl    = boost::mpl;
    
    // given a field, returns a fusion pair of <field, field::type>
    template<class field>
    struct make_pair
    {
        typedef typename fusion::result_of::make_pair<field, typename field::type>::type type;
    };
    
    // given a sequence of fields, returns a fusion map which maps field -> field::type
    template<class... fields>
    struct make_map
    {
        typedef typename boost::fusion::vector<fields...> vector;
        typedef typename mpl::transform<vector, make_pair<mpl::_1>>::type pair_sequence;
        typedef typename fusion::result_of::as_map<pair_sequence>::type type;
    };
    
    // initialise each member of a map with the corresponding element in the vector
    template<typename vector>
    struct init
    {
        init(vector& v) : _v(v) {}
    
        template <typename pair>
        void operator()(pair const& data) const
        {
           // TODO: use pair::first_type to find the index of this pair in the map, and set 
           // data.second to at_c<index>(_v);
        }
        vector& _v;
    };
    
    struct field1 { typedef int type; };
    struct field2 { typedef int type; };
    
    struct my_map
    {
        template<typename... args>
        my_map(args... a)
        {
            typedef typename boost::fusion::vector<args...> vector;
            vector arg_vec(a...);
            
            fusion::for_each(_map, init<vector>(arg_vec));
        }
        typedef typename make_map<field1, field2>::type map;
        map _map;
    };
    
    struct print
    {
        template <typename pair>
        void operator()(pair const& data) const
        {
            std::cout << data.second << " ";
        }
    };
    
    
    int main()
    {
        my_map m(1, 2);
        fusion::for_each(m._map, print()); // should print '1 2'
        return 0;
    }