簡體   English   中英

boost::fusion::result_of::as_set(或 as_vector)從復雜(嵌套)mpl 序列轉換而來

[英]boost::fusion::result_of::as_set (or as_vector) converted from complex (nested) mpl sequences

#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< node_a, node_b, node_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< node_c, node_b, node_a >。

我是否遺漏了任何要指定的內容,例如標簽、大小或? 謝謝!

解決方案比最初出現的要簡單得多::)

你錯過了一些關鍵的東西:

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因此 restore_fusion_set 的類型實際上是as_set<restored_set_type> restored_fusion_set這不是必需的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM