C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了C语言的Boost.Range – 得到元素类型的元组?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在试验Boost.Range和Boost Tuple.如果我有一个范围元组,我如何键入一个元组相应的元素值?换句话说,我用什么代替/ *?* /这里:

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;

但我认为应该可以直接从TupLeofRanges派生TupLeofElements,无论元组大小如何.欢迎任何想法!

编辑:这似乎工作,谢谢@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 :: transform和你编写为functor的typedef链!

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

大佬总结

以上是大佬教程为你收集整理的C语言的Boost.Range – 得到元素类型的元组?全部内容,希望文章能够帮你解决C语言的Boost.Range – 得到元素类型的元组?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。