2011-07-06 10 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 벡터와 같은)에서 융합 시퀀스 (result_of :: as_set 또는 as_vector를 통해)로 처리 된 mpl 시퀀스를 변환하려고하면 컴파일 타임 오류가 발생합니다.부스트 :: 융합 :: result_of :: as_set (또는 as_vector는) 복잡한 (중첩) MPL 시퀀스로 변환 :: 부스트 : : MPL : 벡터 < node_a, Node_B는, node_c 같은 간단한 MPL 시퀀스에서

struct node_c 
struct node_b 
struct node_a 

,하지만 :: MPL : 벡터 < node_c을 강화 :: 간단한 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을 놓친 - 필요한 것이 아닙니다.