草庐IT

any_iterator

全部标签

c++ - 为什么 std::set<K, C, A>::erase 不采用 const_iterator?

看来,根据ISO148822003(又名C++的神圣标准)std::set::erase需要iterator作为参数(不是const_iterator)from23.3.3[2]voiderase(iteratorposition);可能还值得注意的是,在我的VS2008附带的STL实现中,删除需要一个const_iterator。当我试图用另一个编译器编译我的代码时,这导致了一个不愉快的惊喜。现在,因为我的版本需要const_iterator,然后可以用const_iterator实现删除(好像这不是不言而喻的)。我想标准委员会已经考虑了一些实现(或手头现有的实现),这需要删除才能采

c++:const_iterator 和 for-each 循环

我正在用C++实现自己的Vector。这是一个由两部分组成的问题。第1部分:尝试遍历Vector时,我的begin()和end()迭代器无法处理输入参数。下面是我的整个Vector.h实现:classiterator{public:typedefstd::random_access_iterator_tagiterator_category;typedefTvalue_type;Vector*ptr;uint64_tposition;COMLINKslave;voidinit(void){ptr=nullptr;position=0;}voidcopy(constiterator&i)

c++ - GCC 无法向量化这个简单的循环 ('number of iterations cannot be computed' ) 却在同一代码中管理了一个类似的循环?

所以,我有这个循环的C++代码:for(i=0;i所有涉及的数量都是int的。从GCC的矢量化报告中我得到:babar.cpp:233:note:=====analyze_loop_nest=====babar.cpp:233:note:===vect_analyze_loop_form===babar.cpp:233:note:===get_loop_niters===babar.cpp:233:note:notvectorized:numberofiterationscannotbecomputed.babar.cpp:233:note:badloopform.我想知道为什么“无法

c++ - 什么是 raw_storage_iterator 组件在 C++ 中的用途/优势

我正在阅读关于raw_storage_iterator的TC++PL零件。使用这个组件我们可以获得性能优势,因为它避免了分配(更昂贵)并使用复制构造。在我看来,它应该用在我们可以拥有大量元素的序列/容器中,因此赋值调用的数量可能会产生很大的影响。理论上它很清楚,在我看来这个组件对容器类型类很有用。但是我想详细了解我们应该在哪里使用这个组件(通过实际示例)来获得它的性能优势? 最佳答案 在cppreference有示例代码。您可以通过多种机制分配对齐的未初始化内存块。Cppreferences使用std::get_temporary_

c++ - std::any 用于不能复制构造的对象

我有一个包含unique_ptr的对象,因此如果不进行深度复制(我不想要)就无法进行复制构造。我想让std::any持有那个对象,但我发现的唯一替代方法是让std::any持有一个指针,这会增加一个无用的间接寻址,或者让我的对象有一个唯一的指针。下面的代码有望说明我的观点://Compiledwithclang++-std=c++2a;clangversion5.0.0#include#include#includestructA{std::unique_ptrm=std::make_unique(11);A(A&&a):m(std::move(a.m)){}A(){}};struct

c++ - 返回对 boost::any 持有的数据的引用

我有一个任何指针的映射,称为gmap,定义如下:std::map&gmap=getSingleton().globalValues;这张map确实是对globalValues的引用,我已经在gdb中查看了地址。我还控制了any指针(这就是为什么它们是指针,我宁愿做引用,但我现在正在调试)。现在,我用我声明gmap的相同方法返回它:returnboost::any_cast(*gmap[key]);在&boost::any_cast[T&][*gmap[key]]处观察内存,一旦我弹出堆栈帧,数据就会变坏。这很奇怪,因为根据:Boost'sdocumentationofany_cast返

c++ - Boost Single Pass Iterator 和 Forward Traversal Iterator 有什么区别?

在NewIteratorConceptsstandardproposal,我无法破译单遍迭代器和前向遍历迭代器之间的任何有用区别。前向遍历表中“++r”行的“断言/注释”是否暗示前向遍历迭代器是可复制的,而单遍迭代器不是?此外,为什么默认构造的额外能力会产生迭代器模型正向遍历?原理是什么? 最佳答案 单遍迭代器的想法是它比正向遍历迭代器具有更少的要求。这样就可以为某些无法进行多次传递的情况创建一个。想想控制台输入。即使您可以复制迭代器,也无法帮助您检索旧的键盘输入。 关于c++-Boos

C++11 regex_token_iterator

嗯...我以为我理解正则表达式,我以为我理解迭代器,但C++11的正则表达式实现让我感到困惑...一个我不明白的地方:阅读regextokeniterators,我遇到了以下示例代码:#include#include#include#include#includeintmain(){std::stringtext="Quickbrownfox.";//tokenization(non-matchedfragments)//Notethatregexismatchedonlytwotimes:whenthethirdvalueisobtained//theiteratorisasuffi

c++ - boost::any 的访客模式

我找到了这个https://gist.github.com/2945472但我需要一个不依赖于c++11的实现。我尝试将其转换为仅使用boost,但遇到了一些麻烦。这是我想出的:#include#include#include#include#includestructtype_info_hash{std::size_toperator()(std::type_infoconst&t)const{returnt.hash_code();}};structequal_ref{templatebooloperator()(boost::reference_wrappera,boost::r

c++ - 迭代器 - vector::iterator 和 array::iterator 的重载函数

我只是想重载某个函数连续容器的迭代器(它们是std::vector::iterator、std::array::iterator和内置数组迭代器==原始指针)可以是有效参数。出于某种原因,我的函数无法针对vector和std::array进行编译:功能:templatevoidcatchIterator(typenamestd::array::iteratorit){//dosomthing}templatevoidcatchIterator(typenamestd::vector::iteratorit){//dosomthing}使用示例:std::arrayarr;autoit=