问题标签 [const-iterator]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
44 浏览

c++ - 从地图访问几个参数

我定义了一张地图,

条目通过键和值字符串动态填充,元素和序列的数量是动态的..

现在我必须从我知道键的地图中检索 7 个参数,例如, hostName, port, user1,user2user3

一种方法是访问所有 5 个参数并拥有 5 个语句,例如 ..

和访问iterparam1->second.data()iterparam2->second.data()..

这种简单的方法可以完成它的工作,因为我知道地图中的子集,但是我想讨论一下这种方法是否有任何替代方法,以及当前经文与建议/替代方法的优缺点。

谢谢你的时间 :)

0 投票
2 回答
505 浏览

c++ - const_iterator 错误的间接运算符

这段代码

在 Apple LLVM 编译器 4.2 中产生以下错误:

但是,如果我在 LLVM GCC 4.2 中编译此代码,它就可以正常工作。有任何想法吗?

0 投票
1 回答
336 浏览

qt - QHash 无法从 'class QHash 转换参数 1::const_iterator' 到 '::iterator'

我有一个用键值对定义为 QDomElement 的 qhash。如下所示。我正在尝试使用 const_iterator 更新哈希。但是这样做会引发以下错误,如何解决相同的问题:-

代码片段:-

谢谢,普里扬卡

0 投票
0 回答
192 浏览

c++ - C++11: Why does this work in one method but not another in the same class? Iterators morphing into const const_iterators?

I'm writing a range_map container, which stores data in ranges, allowing you to, pick a point and get the ranges that cover it. As a rule, when a range is inserted, its start point and end point must each be covered by the same ranges--causing a kind of pyramid buildup of ranges.

Ranges that are subsets of other ranges have those other ranges as parents. I'm just about done with it and am debugging it when I went through this weird problem. Here's a private method--it's a helper method--from the container, where the error occured:

OK, iterator is typedef'd from the wrapped container's iterator.

  • range_type is the type that is stored in the wrapped container.
  • parent is the parent range, which is also stored as an iterator.

The problem is in the lines where _i->parent is assigned either _end or _start. It comes back with error c2678. Now, for me, this is in Japanese, but it says that the left operand for each of the two lines pointed is of the type const std::_Tree_const_iterator<_Mytree>; therefore, it cannot be assigned anything.

Why it considers the left operand to be a const const_iterator, I don't know, but that is the error. (parent, by the way, is declared as an iterator in range_type.) What's really funny is that in another method (a public method in the same class this time) I do the exact same thing with parent from an iterator and it appears to compile fine--this public method comes before the private method above in the code. Here is the public method:

Though this method in the code comes before the one that gave the error, no error was given for the line where _i->parent was assigned a value.

What is going on here? Why does the iterator seem to morph into a const const_iterator? I hope I was detailed enough.

EDIT: Here's the rest of the output, translated:

This is so so cryptic. I can't make heads or tails of it, and I can't understand why the same didn't occur in that other function. Is it because it returns a pair with an iterator in it, or something? Some weird complex thing?

0 投票
1 回答
476 浏览

c++ - C++ std::vector::const_iterator 问题

所以我对 C++ 比较陌生,我对以下 std::vector::const_iterator 有疑问:

GetSubNodes 访问器

基本上得到一个运行时错误,其中 itr 应该是一个常规的迭代器。有人知道我哪里出错了吗?可能是一个非常简单的问题,但我现在没有看到它。

0 投票
3 回答
243 浏览

c++ - 既然 C++11 缺少它,如何实现 const_auto?

C++11的auto类型很方便,所以现在也想要一个const_auto类型。例如,假设std::list<T> a;,如果

有类型std::list<T>::iterator,然后希望

有类型std::list<T>::const_iterator。不幸的是,C++11 似乎没有听说过const_auto. 因此,如何才能以良好的风格达到预期的效果?

(有关信息,请在此处询问和回答相关问题。

0 投票
1 回答
561 浏览

cuda - 用 const 源推 copy_if

我的问题出在以下代码中:

当源不是恒定的(迭代器相应地调整)时,过滤器函数编译并运行。但是,当我将源更改为 const 时,编译器为 copy_if 语句的前两个变量给出了以下错误:“对象具有与成员函数不兼容的类型限定符”。

我相信某处存在 const to not const 转换错误,但坦率地说,我不知道在哪里。任何帮助,将不胜感激。

我发现用TheOther.cbegin() / .cend()以下编译器替换它会接受它。这意味着我在 typedef 部分的某个地方搞砸了,但是在哪里呢?

0 投票
2 回答
1052 浏览

c++11 - “auto it = unordered_map.find(key)”的推断类型?

随着 C++11 的出现,我们有 unordered_map.cbegin/cend 专门返回我们的 const_iterator 值。所以表达式“auto it = unordered_map.cbegin()”中“it”的推导类型是 const_iterator。

但是,当涉及到 unordered_map.find(key) 函数时,我认为可能缺少一个“cfind()”对应项,它专门返回一个 const_iterator。

有人说我们可以使用“const auto it = unordered_map.find(key)”来获得一个“const iterator”,但我强烈怀疑“const iterator”是同一个“const_iterator”,其中“const iterator”有限制更改迭代器本身的能力,而“const_iterator”限制了更改迭代器所指内容的能力。

所以,真的,如果我们想充分利用“auto”类型推导(了解混淆或“auto”类型推导的变体 - auto、auto&、const auto& 等),我怎么能拥有 unordered_map .find(key) 返回一个“const_iterator”,而无需我明确指定“const_iterator”——毕竟这是 auto 的最佳用例!

下面是一个演示编译器行为的简单示例代码:

0 投票
2 回答
367 浏览

c++ - 依赖范围内的类型名

下面是我的代码的精简版本,它给了我一个编译器错误。编译器告诉我将 typename 放在 'std::deque::reverse_iterator' 前面,这是有道理的。但如果我这样做,我会在底部收到错误。这是什么意思?如何解决?

错误:

0 投票
2 回答
205 浏览

c++ - C++ const_iterator 不可取消引用?

尝试使用 const_iterators 时出现运行时错误。错误是:列表迭代器不可取消引用。我知道无法取消引用 const_iterator 以将值分配到列表中,但我试图取消引用迭代器以访问列表中的值。我正在使用 Visual Studio 2010 专业版。

我对此进行了很多研究,但没有发现任何可以帮助我理解我做错了什么的东西。