我想写一个复杂的算法列表,必须应用于范围序列。我想使用类似于以下代码的语法来嵌套许多算法。我唯一的问题是它不会编译。有什么建议么?结合增强范围算法,例如。升压::复制和提升:: remove_if
bool pred(double x);
double d[]={1,2,3,4};
std::vector<double> x(d,d+4);
std::vector<double> y;
boost::copy(x, std::back_inserter(y)); // OK
boost::copy(boost::remove_if(x,&pred), std::back_inserter(y)); // ERROR
对于这种语法的工作,我不想为内部算法指定模板参数。这可以通过使用auto关键字来简化,但我需要保持代码向后兼容。
这是错误消息的片段:
1>c:\dev\thirdparty\boost\boost-1.48.0-windows-vc90-x32-p64925\installed\include\boost-1_48\boost/range/iterator.hpp(63) : error C2039: 'type' : is not a member of 'boost::mpl::eval_if_c<C,F1,F2>'
1> with
1> [
1> C=true,
1> F1=boost::range_const_iterator<std::_Vector_iterator<double,std::allocator<double>>>,
1> F2=boost::range_mutable_iterator<const std::_Vector_iterator<double,std::allocator<double>>>
1> ]
1> c:\dev\thirdparty\boost\boost-1.48.0-windows-vc90-x32-p64925\installed\include\boost-1_48\boost/range/concepts.hpp(256) : see reference to class template instantiation 'boost::range_iterator<C>' being compiled
1> with
1> [
1> C=const std::_Vector_iterator<double,std::allocator<double>>
1> ]
1> c:\dev\thirdparty\boost\boost-1.48.0-windows-vc90-x32-p64925\installed\include\boost-1_48\boost/concept/detail/has_constraints.hpp(42) : see reference to class template instantiation 'boost::SinglePassRangeConcept<T>' being compiled
1> with
1> [
1> T=const std::_Vector_iterator<double,std::allocator<double>>
1> ]
1> c:\dev\thirdparty\boost\boost-1.48.0-windows-vc90-x32-p64925\installed\include\boost-1_48\boost/concept/detail/msvc.hpp(53) : see reference to class template instantiation 'boost::concepts::not_satisfied<Model>' being compiled
1> with
1> [
1> Model=boost::SinglePassRangeConcept<const std::_Vector_iterator<double,std::allocator<double>>>
1> ]
1> c:\dev\thirdparty\boost\boost-1.48.0-windows-vc90-x32-p64925\installed\include\boost-1_48\boost/range/algorithm/copy.hpp(33) : see reference to class template instantiation 'boost::concepts::require<Model>' being compiled
1> with
1> [
1> Model=boost::SinglePassRangeConcept<const std::_Vector_iterator<double,std::allocator<double>>>
1> ]
1> ..\..\..\..\..\source\yotta\libraries\snl\unittests\StackOverflow.cpp(7) : see reference to function template instantiation 'OutputIterator boost::range::copy<std::_Vector_iterator<_Ty,_Alloc>,std::back_insert_iterator<_Container>>(const SinglePassRange &,OutputIterator)' being compiled
1> with
....
执行范围必须按引用传递?或者他们可以是一个包含对范围的引用的类? – Adrian 2012-02-15 12:14:44
+1“我唯一的问题是它不会编译”。 'cout << the_answer_to_it_all();'唯一的问题是不能编译... – 2012-06-19 11:09:26