Question

I am new to fusion. Is it possible to nest a fusion map inside a fusion map? How do i write code to resolve to B at the below example?

#include <boost/asio.hpp>
#include <boost/fusion/container/map.hpp>
#include <boost/unordered_map.hpp>

struct A 
{
};

struct B
{
};

int main()
{
    boost::fusion::map<
        boost::fusion::pair<
            A, 
            boost::fusion::map<boost::fusion::pair<unsigned int, B>>
        >
    > map_;

    B b = boost::fusion::at_key<unsigned int>((boost::fusion::at_key<A>(map_)); //compile error
}
Was it helpful?

Solution

Aside from the syntax error (an extra parenthesis), you're merely missing some #includes. This works fine for me:

#include <boost/fusion/include/at_key.hpp>
#include <boost/fusion/include/map.hpp>
#include <boost/fusion/include/pair.hpp>

struct A { };
struct B { };

int main()
{
    boost::fusion::map<
        boost::fusion::pair<
            A, 
            boost::fusion::map<boost::fusion::pair<unsigned int, B>>
        >
    > map_;

    B b = boost::fusion::at_key<unsigned int>(boost::fusion::at_key<A>(map_));
}

Online Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top