C ++ Tuple Boost.Range - 获取元素类型的元组? [英] C++ Tuple of Boost.Range - get Tuple of element types?
问题描述
我正在试验Boost.Range和Boost元组。如果我有一个范围的元组,我如何typedef一个元组或相应的元素值?换句话说,我在 / *?* /
这里代替
I am experimenting with Boost.Range and the Boost Tuple. If I have a Tuple of ranges, how can I typedef a Tuple or the corresponding element values? To put this another way, what do I put in place of /*?*/
here:
typedef boost::tuples::tuple<std::vector<int>&, char[]> TupleOfRanges;
typedef /*?*/ TupleOfElements;
我可以手工做,当然,我会写:
I can do this by hand, of course and I would write:
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
,无论元组大小。任何想法欢迎!
But I think it should be possible to derive TupleOfElements
directly from TupleOfRanges
, whatever the tuple size. Any ideas welcome!
编辑:这似乎工作,感谢@ltjax:
this seems to work, thanks @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;
推荐答案
使用 boost :: mpl
Use boost::mpl::transform
with that typedef chain you wrote as the functor!
请参阅 http://www.boost.org/doc/libs/1_47_0/libs/mpl/doc/refmanual/transform .html
这篇关于C ++ Tuple Boost.Range - 获取元素类型的元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!