我正在试验 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;