2011-07-06 12 views
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 

コンバージョン>融合配列にうまく働きます。 しかし、後処理されたmplシーケンスを複雑なmplシーケンス(ネストされたmplベクタなど)からフュージョンシーケンス(result_of :: as_setまたはas_vectorを通して)に変換しようとすると、コンパイル時エラーが発生しました。ブースト::融合:: result_of :: AS_SET(又はas_vector)は、複雑な(ネスト)MPL配列から変換::ブースト:: MPL ::ベクトル<ノードA、ノードB、node_cような単純なMPL配列から

struct node_c 
struct node_b 
struct node_a 

、:: MPL ::ベクトル< node_cを後押し:: SimpleはMPL配列と、それは違ういくつかの種類の情報を、失っているようだ:

"restored_set_type" の印刷があります、node_b、node_a>である。

tag、size、またはのような指定がありませんでしたか?ありがとう!

答えて

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; 

あなたは、単にrestored_fusion_setタイプが実際as_set<restored_set_type>あるので、::typeを逃しましたこれは必要なものではありません。

関連する問題