草庐IT

transform_iterator

全部标签

c++ - transform_primary() 和 collat​​e_byname()

为了给出我所说的上下文,以下程序正确打印true使用clang++/libc++编译时#include#includeintmain(){std::locale::global(std::locale("en_US.UTF-8"));std::wstringstr=L"AÀÁÂÃÄÅaàáâãäå";std::wregexre(L"[[=a=]]*",std::regex::basic);std::cout但是,我不太明白std::regex_traits::transform_primary()的描述。在标准中(通过它处理[=a=])。引用28.7[re.traits]/7:ifty

c++ - std::map::iterator 是否返回值的拷贝或值本身?

我正在尝试在map中创建map:typedefmapinner_map;typedefmapouter_map;我能否在内部map中放一些东西,或者iterator::second返回一个拷贝?STL_pair.h建议后者:74:_T2second;///但我的测试程序运行良好,代码如下:it=my_map.lower_bound(3.1415);(*it).second.insert(inner_map::value_type(2.71828,"Helloworld!");那么真相在哪里?这是不是拷贝? 最佳答案 我想为使用C++

c++ - 为什么 "transform(s.begin(),s.end(),s.begin(),tolower)"编译不成功?

给定代码:#include#include#include#includeusingnamespacestd;intmain(){strings("ABCDEFGHIJKL");transform(s.begin(),s.end(),s.begin(),tolower);cout我得到错误:Nomatchingfunctionforcalltotransform(__gnu_cxx::__normal_iterator,std::allocator>>,__gnu_cxx::__normal_iterator,std::allocator>>,__gnu_cxx::__normal_i

c++ - move_iterator 是做什么用的

如果我理解正确,a=std::move(b)将引用a绑定(bind)到b的地址。而且这个操作之后b指向的内容是不保证的。move_iterator的实现here有这条线autooperator[](difference_typen)const->decltype(std::move(current[n])){returnstd::move(current[n]);}但是,我认为std::move数组中的元素没有意义。如果a=std::move(b[n])会发生什么?下面的例子也让我很困惑:std::stringconcat=std::accumulate(std::move_itera

c++ - Boost 1.46.1,属性树 : How to iterate through ptree receiving sub ptrees?

首先我要说我认为我知道应该怎么做,但是我的代码不会以我尝试的任何方式编译。我的假设基于thisofficialexampleofemptyptreetrick.在那里你可以找到下一行:constptree&settings=pt.get_child("settings",empty_ptree());这表明可以(或应该)从ptree中取出subptree。所以我假设我们可以用类似BOOST_FOREACH这样的方式遍历ptree:BOOST_FOREACH(constboost::property_tree::ptree&v,config.get_child("servecies"))

c++ - std::transform 使用 C++0x lambda 表达式

这是如何在C++0x中完成的?std::vectormyv1;std::transform(myv1.begin(),myv1.end(),myv1.begin(),std::bind1st(std::multiplies(),3));原始问题和解决方案是here. 最佳答案 std::transform(myv1.begin(),myv1.end(),myv1.begin(),[](doubled)->double{returnd*3;}); 关于c++-std::transform使

c++ - iter_swap 的意义何在?

我只是想知道,为什么有人会写这个:std::iter_swap(i,k);而不是这个?std::swap(*i,*k);//savedafewkeystrokes!然后我研究了iter_swap的实现,当然它只使用swap而不是std::swap因为我们是无论如何,已经在namespacestd中了。这就引出了下一个问题:为什么会有人写这个:usingstd::swap;swap(a,b);而不是这个?std::iter_swap(&a,&b);//savedanentirelineofcode!我在这里忽略了任何重要的差异/问题吗? 最佳答案

c++ - CppCon 2018,尼古拉 Josuttis : Why are these interpreted as iterators?

NicolaiJosuttis在CppCon2018上的“C++初始化的噩梦”演讲曾一度包含以下代码:std::vectorv07={{"1","2"}};尼古拉saidthefollowing(我的转录本):Theproblemis,whathappenshereis,weinterpretthesetwoparametersasiterators.Sotheseareiterators,sothisisthebeginningoftherange,andthisistheendoftherange,andtheyshouldrefertothesamerangeofcharacte

c++ - const_iterators 更快吗?

我们的编码指南更喜欢const_iterator,因为它们比普通的iterator快一点。当您使用const_iterator时,编译器似乎会优化代码。这真的正确吗?如果是,那么内部究竟发生了什么使const_iterator更快?。编辑:我写了一个小测试来检查const_iterator与iterator并发现不同的结果:迭代10,000个对象const_terator减少了几毫秒(大约16毫秒)。但并非总是。有一些迭代是相等的。 最佳答案 如果没有别的,const_iteratorreads更好,因为它告诉任何阅读代码的人“我只

c++ - 为什么不推荐使用 std::iterator ?

模板类std::iterator在C++17中设置为弃用。为什么这样?这是确保std::iterator_traits的便捷方法。有效,特别是如果您可以使用默认模板参数。在C++17中还有其他方法吗? 最佳答案 来自theproposalthatsuggesteditsdeprecation:Asanaidtowritingiteratorclasses,theoriginalstandardlibrarysuppliedtheiteratorclasstemplatetoautomatethedeclarationofthefiv