2017-10-14 58 views
0

考慮:升壓MPL - 做變換上joint_view

template<typename T> 
struct MakeVectorOfType 
{ 
    typedef std::vector<T> type; 
}; 

typedef boost::mpl::vector<int, double> TScalarTypes; 
typedef boost::mpl::transform<TScalarTypes, MakeVectorOfType<boost::mpl::placeholders::_1>>::type TVectorTypes; 
typedef boost::mpl::joint_view<TScalarTypes, TVectorTypes>::type TTypes; 

template<typename T> 
struct Wrapper 
{ 
    T value; 
}; 

template<typename T> 
struct MakeWrapper 
{ 
    typedef Wrapper<T> type; 
}; 

typedef boost::mpl::transform< 
    TScalarTypes::type, 
    MakeWrapper<boost::mpl::placeholders::_1> 
>::type TScalarWrapperTypes; // <-- Works 

typedef boost::mpl::transform< 
    TTypes::type, 
    MakeWrapper<boost::mpl::placeholders::_1> 
>::type TAllWrapperTypes; // <-- Compiler error 

所以基本上我在MPL序列某些類型的,我再拍序列具有的std ::這些類型的載體,那麼我想要做的事與兩者的結合。如果我想這樣做對工會另一變換(使用joint_view),我得到以下編譯器錯誤(使用MSVC2017):

1>e:\source\trunk\thirdparty\boost\mpl\clear.hpp(31): error C2504: 'boost::mpl::clear_impl<boost::mpl::aux::joint_view_tag>::apply<Sequence>': base class undefined 
1>  with 
1>  [ 
1>   Sequence=boost::mpl::joint_view<TScalarTypes,TVectorTypes> 
1>  ] 

(......再加上很多回溯到上面的代碼,很明顯)

另一個(我直接在序列上進行轉換的)工作正常,所以AFAICT是在這裏將問題應用於joint_view上的轉換的組合。那麼這是因爲joint_view不是一個「真實」的序列,而僅僅是一個「視圖」?我可以先製作一個joint_view的副本,然後在該副本上應用轉換,但這只是讓我感到無法一氣呵成。

回答

0

看來mtl :: transform無法處理由joint_view生成的序列。 joint_view生成一個mtl :: transform可能不支持的'懶惰轉發序列'。

您可以使用boost :: MPL ::複製下面要解決的問題,

typedef typename boost::mpl::copy<TVectorTypes, boost::mpl::back_inserter<TScalarTypes> >::type TTypes;