草庐IT

make_transform_iterator

全部标签

c++ - 为什么 sizeof...(T) 这么慢?在没有 sizeof...(T) 的情况下实现 C++14 make_index_sequence

我找到了C++14make_index_sequence“算法”的实现:templatestructindex_sequence{usingtype=index_sequence;};templateusinginvoke=typenameT::type;templatestructconcate;templatestructconcate,index_sequence>:index_sequence{};//\///----------//Ithinkhereisslowly.templatestructmake_index_sequence_help:concate>,invoke

c++ - 为什么箭头运算符 "->"不能在 boost::numeric::ublas::vector<...>::iterator 上工作?

考虑这段代码:structCData{intbar(){return1;}};intmain(){typedefboost::numeric::ublas::vectorvec_data_t;vec_data_tfoo;for(vec_data_t::iteratorit=foo.begin();it!=foo.end();++it){std::coutbar()为什么循环中使用箭头运算符的第一行编译失败,而使用运算符*的下一行编译正常?我习惯于将箭头运算符与std容器迭代器一起使用,想知道为什么它在boost::numeric::ublas迭代器上失败。我使用的是boost1.54和

c++ - std::transform 到任意容器

我想编写通用函数,它接收container1的值为[a1,..,an]并返回另一个container2的值为[转换(a1),..,转换(an)]。如果container2是std::vector,问题就微不足道了,std::transform完全符合我的要求。下面的函数可以处理任意的container2和container1templateToTypeconvert(constFromType&from){std::vectortmp;std::transform(from.begin(),from.end(),std::back_inserter(tmp),[](consttypen

c++ - 在 C++ 中将惰性生成器实现为 forward_iterator

MyGenerator代表一个(可能)有限的整数序列,计算起来很昂贵。所以我不想预先生成它们并将它们放入容器中。structMyGenerator{boolHasNext();intNext();}全部打印:MyGeneratorgenerator;while(generator.HasNext()){std::cout如何实现类似的遵循forward_iterator协议(protocol)的生成器?boost::function_input_iterator接近,但我不知道预先元素的数量。 最佳答案 首先,查看boost::fu

c++ - 如何检查迭代器是否是 C++ 中的 output_iterator?

templatevoidput_value(Iteratorpos,intn){static_assert(IsOutputIterator);////HowtoimplementIsOutputIterator?//*pos=n;}std::iterator_traits::iterator_category没有帮助。例如:vector::iterator很明显是一个output_iterator,但是std::iterator_traits::iterator>::iterator_category将返回random_access_iterator,可能不是output_itera

c++ - 什么是未知大小的 make_shared?

在this回答T.C.州boost::make_sharedetc.supportarraytypes-eitheroneofunknownsize,oroneoffixedsizeboost::shared_ptrsh_arr2=boost::make_shared(30);boost::shared_ptrsh_arr3=boost::make_shared();首先,make_shared如何支持未知大小的数组类型?我认为数组大小是必需的。其次,sh_arr2和sh_arr3有什么区别?两者似乎都在创建一个int大小为30的数组。 最佳答案

c++ - 并行 STL 是否处理插入迭代器,例如 std::back_insert_iterator?

并行STL算法是否符合std::back_insert_iterator??我可能误解了std::par和std::par_vec之间的区别,std::par_vec是否意味着输出范围是否需要预先分配?代码示例:autonumbers={1,2,3,4,5,6};autosquared=std::vector{};std::transform(**std::par/std::par_vec,**numbers.begin(),numbers.end(),std::back_inserter(squared),[](autoval){returnval*val;});更新简化问题,因为我

c++ - std::transform 以两个 std::vector 和一个常量作为参数

我想使用std::transform做一些类似于binary_op的事情,但有一个额外的常量,例如,得到两个vector的乘积:x1=(10,20,30,40,50)和x2=(2,4,6,8,10),我们可以写成:#include#include#includedoublemultiply(doublex,doubley){returnx*y;}intmain(){std::vectorx1;std::vectorx2;for(inti=1;i::iteratorit=x1.begin();it!=x1.end();++it)std::cout以上代码将按元素乘以x1和x2并返回(20

c++ - std::wostream_iterator

为什么C++中没有std::wostream_iterator?这有什么好的理由吗?#include#include#include#includeintmain(){std::vectormyvec={L"first",L"second"};std::wofstreamf("New.txt");//std::copy(myvec.begin(),myvec.end(),std::wostream_iterator(f));//Error//std::copy(myvec.begin(),myvec.end(),std::ostream_iterator(f));//Errorstd:

c++ - forward_list::splice_after( const_iterator pos, forward_list& other, const_iterator i ) 功能

我正在阅读有关此功能工作方式的不同解释。cplusplus.com说这个函数应该“直接在i之后移动元素”。然而cppreference.com表示它拼接元素ATi。MSvisualstudio同意cplusplus.com。但是,实际上正确的行为是什么?我倾向于认为“在i之后”移动更合乎逻辑(&不需要N时间来找到前面的节点)。(PS:没有forward-list标签?) 最佳答案 23.3.4.6voidsplice_after(const_iteratorposition,forward_list&x,const_iterator