4

我正在试验 Boost.Range 和 Boost Tuple。如果我有一个范围的元组,我如何 typedef 一个元组或相应的元素值?换句话说,我在这里放什么/*?*/

typedef boost::tuples::tuple<std::vector<int>&, char[]> TupleOfRanges;
typedef /*?*/ TupleOfElements;

当然,我可以手动完成,我会写:

typedef boost::tuples::tuple<int, char> TupleOfElements;

甚至:

typedef typename boost::tuples::element<0, TupleOfRanges>::type Range0;
typedef typename boost::tuples::element<1, TupleOfRanges>::type Range1;
typedef typename boost::range_iterator<Range0>::type Iterator0;
typedef typename boost::range_iterator<Range1>::type Iterator1;
typedef typename boost::iterator_value<Iterator0>::type Value0;
typedef typename boost::iterator_value<Iterator1>::type Value1;

typedef boost::tuples::tuple<Value0, Value1> TupleOfElements;

但我认为无论元组大小如何,都应该可以TupleOfElements直接从中派生。TupleOfRanges欢迎任何想法!

编辑:这似乎有效,谢谢@ltjax:

struct GetIteratorType
{
    template <class Range>
    struct apply
    {
        typedef typename boost::range_iterator<Range>::type type;
    };
};
typedef boost::mpl::transform<TupleOfRanges, GetIteratorType> TupleOfIterators;

struct GetElementType
{
    template <class Iterator>
    struct apply
    {
        typedef typename boost::iterator_value<Iterator>::type type;
    };
};
typedef boost::mpl::transform<TupleOfIterators, GetElementType> TupleOfElements;
4

1 回答 1

2

boost::mpl::transform与您作为函子编写的 typedef 链一起使用!

http://www.boost.org/doc/libs/1_47_0/libs/mpl/doc/refmanual/transform.html

于 2011-08-10T12:58:56.883 回答