ReadingLab / Discussion-for-Cpp

C++ 中文讨论区
MIT License
88 stars 63 forks source link

c++primer中文版11.3.3 #40

Closed hexinzhe closed 9 years ago

hexinzhe commented 9 years ago

第一段最后一句说迭代器指定元素被删除,返回void 387页上方表11.5又说,删除迭代器指定元素返回最后被删除的元素的后一个元素迭代器 明显矛盾,前一个是旧标准,后一个是新标准?

pezy commented 9 years ago

@hexinzhe

很抱歉,没有中文版的书。你能简要介绍一下是什么容器,哪一个方法吗?最好有一段示例代码。

hexinzhe commented 9 years ago

11.3.3是关联容器操作中的删除元素 erase方法 在英文434,435页 erase方法有接受一个迭代器或接受迭代器范围的版本: erase(p); erase(b,e) p是一个迭代器,be是一个迭代器范围 我不知道是不是翻译有误什么的,书上的表述前后不一,前面说这两个版本没有返回值,而在后面的11.5表格中说返回一个迭代器

hexinzhe commented 9 years ago

gcc或vs2015中测试均有返回值

pezy commented 9 years ago

英文版的第一段话最后一句如下:

These versions of erase are similar to the corresponding operations on sequential containers: The indicated element(s) are removed and the function returns void.

而 Table 11.5 显然是 Associative containers 特有的。

针对的不同类型容器,并不矛盾。。

hexinzhe commented 9 years ago

这些版本的erase类似于顺序容器,这些 指的不就是关联容器吗?

pezy commented 9 years ago

我理解是这个意思:

hexinzhe commented 9 years ago

更迷茫的是,我朋友说查了c++标准库这本书,书上说关联容器的insert和erase都没有返回值(准确性我不负责)

pezy commented 9 years ago

这有什么可以迷茫的,查一下标准就知道了。

以 std::map 为例,请见其 erase 的定义:http://en.cppreference.com/w/cpp/container/map/erase

image

可以看到,有返回值的版本,显然是有的。。。

hexinzhe commented 9 years ago

好吧,就这样吧

hexinzhe commented 9 years ago

多谢