Boost Fusion / MPL:将类型从序列转换为等效any_range的序列

我想使用Boost的
any_range
来处理多个异构数据范围。我的数据范围的类型称为Fusion矢量,例如:
typedef vector<double, int, char> TypeSequence
鉴于这样的类型,我想编写一个模板来派生另一个类型:
vector<AnyRange<double>::value, AnyRange<int>::value, AnyRange<char>::value>
其中
AnyRange
定义为:
using namespace boost;
template <typename T>
struct AnyRange
{
    typedef typename any_range<typename T, forward_pass_traversal_tag, int, std::ptrdiff_t> value;
};
我尝试过但都失败了。 Fusion甚至可以实现这一点吗? MPL?或者也许我正在用
any_range
走错路。     
已邀请:
您可以使用boost :: mpl :: transform轻松完成此操作,您可以将其与Fusion序列一起使用(只要您包含适当的标头以使Fusion序列表现为确认MPL序列):
#include <boost/range/any_range.hpp>

#include <boost/fusion/include/mpl.hpp> // Required to adapt Fusion to MPL
#include <boost/fusion/include/vector.hpp>

#include <boost/mpl/transform.hpp>


template < typename T >
struct EmbedInAnyRange
{
    typedef boost::any_range< // no need for typename here
        T,                    // no need for typename here
        forward_pass_traversal_tag, 
        int,                  // not sure what this parameter is, I leave int...
        std::ptrdiff_t
    > type;
};

int main()
{
    typedef boost::fusion::vector< double, int, char > Tuple;

    typedef boost::mpl::transform<
        Tuple,
        EmbedInAnyRange< boost::mpl::_ >
    >::type AnyRangeTuple;

    AnyRangeTuple myTuple( 
        std::vector< double >(), 
        std::list< int >(), 
        std::vector< char >() );
}
如果需要,可以将转换放入自己的元函数中:
template < typename Seq >
struct EmbedAllInAnyRange
{
    typedef typename boost::mpl::transform< // typename needed
        Seq,
        EmbedInAnyRange< boost::mpl::_ >
    >::type type;
};

...

typedef EmbedAllInRange< Tuple >::type AnyRangeTuple;
    

要回复问题请先登录注册