[fusion] map_gen interest

Hi, Quite frenquently I'm facing the problem of creating fusion::map where the value can be determined by key using some metafunction. For instance: fusion::map< fusion::pair<int, std::vector<int> >, fusion::pair<char, std::vector<char> >
my_map;
I did not find such ready to use functionality in fusion (may be my miss). So I created utility metafunction to generate such maps. For provided example, the usage of this class is the following: template<class T> struct make_vector { typedef std::vector<T> type; }; typedef mstd::map_gen<boost::mpl::vector<int, char>, make_vector>::type my_map; In other words it takes some fusion sequence and metafunction. The result is fusion map with keys from the specified sequence and values generated from keys using specified metafunction. I've found this metafunction very useful, also it easily solves the problem discussed in boost.user list: "Need boost's help with poor design". May be somebody also interested in this metafuction. Best Regards, Sergei

AMDG Sergei Politov wrote:
For provided example, the usage of this class is the following: template<class T> struct make_vector { typedef std::vector<T> type; };
typedef mstd::map_gen<boost::mpl::vector<int, char>, make_vector>::type my_map;
You should probably use an mpl lambda expression mstd::map_gen<boost::mpl::vector<int, char>, make_vector<boost::mpl::_1>
::type
In other words it takes some fusion sequence and metafunction. MPL sequence? There shouldn't be any runtime information associated with the key.
In Christ, Steven Watanabe

Steven Watanabe <watanabesj <at> gmail.com> writes:
AMDG
Sergei Politov wrote:
For provided example, the usage of this class is the following: template<class T> struct make_vector { typedef std::vector<T> type; };
typedef mstd::map_gen<boost::mpl::vector<int, char>, make_vector>::type my_map;
You should probably use an mpl lambda expression
mstd::map_gen<boost::mpl::vector<int, char>, make_vector<boost::mpl::_1>
::type
Sorry, I'm not very familiar with mpl::lambda, as far as I understand to write make_vector<boost::mpl::_> I should support mpl::lambda in make_vector. If so it is not neccessary, as soon as it is just example, and it does not belong to internal part of map_gen.
In other words it takes some fusion sequence and metafunction. MPL sequence? There shouldn't be any runtime information associated with the key. I meant: "fully conforming fusion sequences". As soon as it is possible to adapt mpl sequence to fusion sequence, I suggest it is better to require fusion sequence concept rather mpl sequence concept. Even runtime information is not used. It produces no overhead, but makes map_gen more flexible.
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

AMDG Sergei Politov wrote:
Sorry, I'm not very familiar with mpl::lambda, as far as I understand to write make_vector<boost::mpl::_> I should support mpl::lambda in make_vector. If so it is not neccessary, as soon as it is just example, and it does not belong to internal part of map_gen.
No. make_vector doesn't have to know about mpl::_. map_gen has to use mpl::apply to make lambda expressions work.
In other words it takes some fusion sequence and metafunction.
MPL sequence? There shouldn't be any runtime information associated with the key.
I meant: "fully conforming fusion sequences". As soon as it is possible to adapt mpl sequence to fusion sequence, I suggest it is better to require fusion sequence concept rather mpl sequence concept. Even runtime information is not used. It produces no overhead, but makes map_gen more flexible.
It's already pretty easy to make such a map using mpl sequences. #include <boost/fusion/container/map.hpp> #include <boost/fusion/include/convert.hpp> #include <boost/fusion/support/pair.hpp> #include <boost/fusion/adapted/mpl.hpp> #include <boost/fusion/sequence/intrinsic/at_key.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/transform.hpp> #include <vector> using namespace boost; using namespace mpl::placeholders; typedef fusion::result_of::as_map< mpl::transform< mpl::vector<int, char, double>, fusion::pair<_, std::vector<_> > >::type
::type map_type;
int main() { map_type map; fusion::at_key<int>(map).push_back(1); fusion::at_key<char>(map).push_back(1); fusion::at_key<char>(map).push_back(1.4); fusion::at_key<int>(map).push_back(1.4); } In Christ, Steven Watanabe

Steven Watanabe <watanabesj <at> gmail.com> writes:
AMDG
No. make_vector doesn't have to know about mpl::_. map_gen has to use mpl::apply to make lambda expressions work.
Ok, I will check it.
It's already pretty easy to make such a map using mpl sequences.
#include <boost/fusion/container/map.hpp> #include <boost/fusion/include/convert.hpp> .................. fusion::at_key<char>(map).push_back(1.4); fusion::at_key<int>(map).push_back(1.4); }
The problem that it is limited by max size of fusion vector. I'm using fusion cons and alternative map class, that avoids this problem. The map_gen itself, without alternative map class is pretty small.
participants (2)
-
Sergei Politov
-
Steven Watanabe