3

我是新来的融合。是否可以在融合地图中嵌套融合地图?在下面的示例中,我如何编写代码以解析为 B?

#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
}
4

1 回答 1

3

除了语法错误(一个额外的括号)之外,您只是缺少一些#includes. 这对我来说很好:

#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

于 2012-11-02T02:53:38.907 回答