3
#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

::boost::mpl::vector< node_a, node_b, node_c > のような単純な mpl シーケンスから融合シーケンスへの変換は正常に機能します。しかし、後処理された 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 > とは異なる型情報を失うようです。

タグ、サイズなど、指定するものがありませんでしたか? ありがとう!

4

1 に答える 1

1

ソリューションは、最初に表示されるよりもはるかに簡単です。:)

あなたは何か重要なことを見逃しています:

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_set実際にはas_set<restored_set_type>is です - これは必要なものではありません。

于 2011-07-06T20:48:07.770 に答える