boost::fusion::result_of::as_set(或as_vector)从复杂(嵌套)mpl 序列转换而来

发布于 2024-11-18 13:22:28 字数 2486 浏览 8 评论 0原文

#include <iostream>
#include <boost/fusion/mpl.hpp>
#include <boost/fusion/include/mpl.hpp>
#include <boost/fusion/container/set.hpp>
#include <boost/fusion/include/at_key.hpp>
#include <boost/fusion/include/as_set.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/set.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/insert.hpp>    

struct node_base
{
    int get() {return 123;}
};
struct node_a : public node_base
{};
struct node_b : public node_base
{};
struct node_c : public node_base
{};

typedef boost::mpl::vector3<
::boost::mpl::vector1<node_a>
,::boost::mpl::vector1<node_b>
,::boost::mpl::vector1<node_c>
>::type nested_vec_type;

typedef ::boost::mpl::fold<
nested_vec_type
, ::boost::mpl::set<>
, ::boost::mpl::insert< 
    ::boost::mpl::placeholders::_1
    , ::boost::mpl::front<::boost::mpl::placeholders::_2>
>
>::type restored_set_type;

typedef ::boost::fusion::result_of::as_set<restored_set_type> restored_fusion_set;

restored_fusion_set my_restored_set;

int main()
{
    std::cout << boost::fusion::at_key<node_a>(my_restored_set).get() << std::endl;
    std::cout << boost::fusion::at_key<node_b>(my_restored_set).get() << std::endl;
    std::cout << boost::fusion::at_key<node_c>(my_restored_set).get() << std::endl;
    return 0;
}



error C2039: 'category' : is not a member of 'boost::fusion::result_of::as_set<Sequence>'
error C2039: 'type' : is not a member of 'boost::fusion::result_of::end<Sequence>'
error C2504: 'boost::fusion::extension::end_impl<Tag>::apply<Sequence>' : base class undefined
error C2039: 'type' : is not a member of 'boost::fusion::result_of::begin<Sequence>'
error C2504: 'boost::fusion::extension::begin_impl<Tag>::apply<Sequence>' : base class undefined
error C2065: 'type' : undeclared identifier

来自简单 mpl 序列的转换,如::boost::mpl::vector<节点_a、节点_b、节点_c>融合序列工作正常。 但是,当我尝试将后处理的 mpl 序列从复杂的 mpl 序列(如嵌套 mpl 向量)转换为融合序列(通过 result_of::as_set 或 as_vector)时,出现编译时错误。

“restored_set_type”的打印输出是:

struct node_c
struct node_b
struct node_a

,但它似乎丢失了一些类型信息,这使得它与简单的 mpl 序列 ::boost::mpl::vector< 不同。节点_c、节点_b、节点_a> 。

我是否遗漏了任何需要指定的内容,例如标签、尺寸或?谢谢!

#include <iostream>
#include <boost/fusion/mpl.hpp>
#include <boost/fusion/include/mpl.hpp>
#include <boost/fusion/container/set.hpp>
#include <boost/fusion/include/at_key.hpp>
#include <boost/fusion/include/as_set.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/set.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/insert.hpp>    

struct node_base
{
    int get() {return 123;}
};
struct node_a : public node_base
{};
struct node_b : public node_base
{};
struct node_c : public node_base
{};

typedef boost::mpl::vector3<
::boost::mpl::vector1<node_a>
,::boost::mpl::vector1<node_b>
,::boost::mpl::vector1<node_c>
>::type nested_vec_type;

typedef ::boost::mpl::fold<
nested_vec_type
, ::boost::mpl::set<>
, ::boost::mpl::insert< 
    ::boost::mpl::placeholders::_1
    , ::boost::mpl::front<::boost::mpl::placeholders::_2>
>
>::type restored_set_type;

typedef ::boost::fusion::result_of::as_set<restored_set_type> restored_fusion_set;

restored_fusion_set my_restored_set;

int main()
{
    std::cout << boost::fusion::at_key<node_a>(my_restored_set).get() << std::endl;
    std::cout << boost::fusion::at_key<node_b>(my_restored_set).get() << std::endl;
    std::cout << boost::fusion::at_key<node_c>(my_restored_set).get() << std::endl;
    return 0;
}



error C2039: 'category' : is not a member of 'boost::fusion::result_of::as_set<Sequence>'
error C2039: 'type' : is not a member of 'boost::fusion::result_of::end<Sequence>'
error C2504: 'boost::fusion::extension::end_impl<Tag>::apply<Sequence>' : base class undefined
error C2039: 'type' : is not a member of 'boost::fusion::result_of::begin<Sequence>'
error C2504: 'boost::fusion::extension::begin_impl<Tag>::apply<Sequence>' : base class undefined
error C2065: 'type' : undeclared identifier

The conversions from simple mpl sequences like ::boost::mpl::vector< node_a, node_b, node_c > to fusion sequences work fine.
But I got compile-time errors when I was trying to convert a after-processed mpl sequence from a complex mpl sequence (like nested mpl vectors) to a fusion sequence (through result_of::as_set or as_vector).

The print out of "restored_set_type" is:

struct node_c
struct node_b
struct node_a

, but it seems to lose some type information, which makes it different from a simple mpl sequence ::boost::mpl::vector< node_c, node_b, node_a > .

Did I miss anything to specify, like tag, size, or? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错爱 2024-11-25 13:22:28

解决方案比最初出现的要简单得多! :)

你错过了一些关键的东西:

typedef ::boost::fusion::result_of::as_set<restored_set_type> restored_fusion_set;

不正确,你需要的是:

typedef ::boost::fusion::result_of::as_set<restored_set_type>::type restored_fusion_set;

你只是错过了 ::type 因此 restored_fusion_settype实际上是 as_set - 这不是所需要的。

the solution is a lot simpler than it first appears! :)

You've missed out something critical:

typedef ::boost::fusion::result_of::as_set<restored_set_type> restored_fusion_set;

Is incorrect, what you need is:

typedef ::boost::fusion::result_of::as_set<restored_set_type>::type restored_fusion_set;

You simply missed ::type hence the type of restored_fusion_set is actually as_set<restored_set_type> - which is not what is required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文