cplusplus.com有什么问题? [英] What's wrong with cplusplus.com?

查看:189
本文介绍了cplusplus.com有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能不是这个问题的完美合适的论坛,但让我给予一个镜头,冒着被移走的风险。

This is perhaps not a perfectly suitable forum for this question, but let me give it a shot, at the risk of being moved away.

有几个参考对于C ++标准库,包括无价的ISO标准, MSDN IBM cppreference cplusplus 。就个人而言,当编写C ++时,我需要一个具有快速随机访问,加载时间和使用示例的引用,我已经发现cplusplus.com非常有用。但是,我经常在这里听到关于这个网站的负面意见,所以我想得到具体:

There are several references for the C++ standard library, including the invaluable ISO standard, MSDN, IBM, cppreference, and cplusplus. Personally, when writing C++ I need a reference that has quick random access, short load times and usage examples, and I've been finding cplusplus.com pretty useful. However, I've been hearing negative opinions about that website frequently here on SO, so I would like to get specific:

错误,误解或坏事cplusplus.com提供的建议?使用它来做出编码决定有什么风险?

What are the errors, misconceptions or bad pieces of advice given by cplusplus.com? What are the risks of using it to make coding decisions?

让我补充一点:我想在这里用标准的标准引用回答问题,因此我想发布立即可用的链接,cplusplus.com将是我的选择网站,因为它不是这个问题。

Let me add this point: I want to be able to answer questions here on SO with accurate quotes of the standard, and thus I would like to post immediately-usable links, and cplusplus.com would have been my choice site were it not for this issue.

更新:有许多伟大的反应,我已经严重改变了我对cplusplus.com的看法。我想在这里列出几个选择结果;

Update: There have been many great responses, and I have seriously changed my view on cplusplus.com. I'd like to list a few choice results here; feel free to suggest more (and keep posting answers).

截至2011年6月29日


  • 某些算法的说明不正确(例如 remove )。

  • 函数的行为有时是不正确的( atoi ),没有提到特殊情况( strncpy )或省略重要信息迭代器失效)。

  • 示例包含已弃用的代码(#include style)。

  • 不准确的术语是对学习者和一般社区STL,编译器与工具链)。

  • typeid 关键字的说明不正确和误导。

  • Incorrect description of some algorithms (e.g. remove).
  • Information about the behaviour of functions is sometimes incorrect (atoi), fails to mention special cases (strncpy), or omits vital information (iterator invalidation).
  • Examples contain deprecated code (#include style).
  • Inexact terminology is doing a disservice to learners and the general community ("STL", "compiler" vs "toolchain").
  • Incorrect and misleading description of the typeid keyword.

推荐答案

编辑 std :: remove 已经固定,因为这个答案写。同样的事情适用于 list :: remove

Documentation for std::remove has been fixed since this answer was written. Same thing applies to list::remove.

让我给你一个例子来告诉你cpluscplus.com

Let me give you an example to show you how cpluscplus.com can get it wrong.

< algorithm>考虑 std :: remove

事实是 std :: remove 从容器。它因为 std :: remove 只使用一对迭代器,并且不知道任何关于实际包含项目的容器。事实上, std :: remove 不可能知道底层容器,因为没有办法从一对迭代器去发现容器迭代器属于。因此 std :: remove 并不真正删除项目,只是因为它不能。从 移除容器中的项目的唯一方法是调用该容器上的成员函数。

The fact is thatstd::remove doesn't remove the item from the container. Its because std::remove works with a pair of iterators only and does not know anything about the container which actually contains the items. In fact, it's not possible for std::remove to know the underlying container, because there is no way it can go from a pair of iterators to discover about the container to which the iterators belong. So std::remove doesn't really remove the items, simply because it cannot. The only way to actually remove an item from a container is to invoke a member function on that container.

项目,然后使用擦除 - 删除成语

 v.erase(std::remove(v.begin(), v.end(), 10), v.end()); 

cplusplus.com 不正确的信息 std :: remove 它说


请注意,此函数不会更改新结尾处的元素,保留旧值仍可访问

Notice that this function does not alter the elements past the new end, which keep their old values and are still accessible.

这不正确。 [new_end,old_end) 范围内的迭代器仍然是可解引用的,但这并不意味着它们保留旧值,

which isn't correct. The iterator in the range [new_end, old_end) is still dereferenceable, but that does NOT mean that they keep the old values and are still accessible. They are unspecified.

同样, cplusplus.com

Similarly, cplusplus.com gives incorrect information about list::remove as well. It says,

请注意,全局算法函数remove是存在类似行为但在两个迭代器之间运行。

Notice that a global algorithm function, remove, exists with a similar behavior but operating between two iterators.

这是完全错误。全局删除 std :: remove 不类似于 list :: remove ,因为我们看到前不会真正删除容器中的项,因为它不能,而后者(成员函数)确实删除

which is completely wrong. The global remove namely std::remove is not similar to list::remove, as we saw that the former does NOT really remove the items from the container because it cannot, whereas the latter (the member function) really does remove the items because it can.

这个答案是从下面主题中的另一个答案复制的,稍加修改:

This answer is copied from my another answer in the following topic, with little modification:

  • STL remove doesn't work as expected?

注意:由于我最近遇到这个问题, , 我记得。在过去两年里,我遇到许多错误,我不记得了。如果我再次遇到,我可能会再添加几个。

Note: Since I came across this recently when I was replying in the above topic, I remember it. There are many errors which I've come across over the last two years, which I don't remember. I might add few more later, if I come across again.

这篇关于cplusplus.com有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆