Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the errors, misconceptions or bad pieces of advice given by cplusplus.com? [closed]

Tags:

c++

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:

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?

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.

like image 760
Kerrek SB Avatar asked Oct 10 '22 21:10

Kerrek SB


2 Answers

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

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

Consider std::remove function from <algorithm>.

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.

So if you want to remove the items, then use Erase-Remove Idiom:

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

But cplusplus.com gives incorrect information about std::remove. It says

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

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.


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

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

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.

like image 77
Nawaz Avatar answered Oct 19 '22 20:10

Nawaz


I'm going to offer an opinion slightly to the contrary. There is lots of good information on cplusplus.com. Pick at it to death, and yes, of course it has its problems, but what site doesn't? Certainly not this site. People who live in glass houses shouldn't throw stones. There is a lot of misinformation here, too. There are accepted answers that are flat-out wrong, downvoted answers (some negative!) that are spot-on correct.

One issue with cplusplus.com is is that it is a closed site; the same goes for most the other reference sites mentioned. This goes against the grain of a community-developed site such as Stack Overflow. Acquiring the ability to make trusted edits doesn't take all that long, and even the newest of newbies can easily make suggestions for improvement. Compare that to cplusplus.com. You are a perpetual newbie if you aren't on their staff. Even if you are a key member of WG21, you have to go through their email report mechanism if you see a bug somewhere in that site. Anathema!

A solution would be for us at this site to develop our own C++ reference. This would take quite a bit of work. We'd have to be careful not to be too pedantic / too technical; it is obvious that cplusplus.com employs at least a few technical editors who keep the pedants at bay. We'd have to keep the information well-organized; the FAQ here are not well organized. We'd also have to be very careful not to spout too much directly from the standard; that's illegal.

like image 41
David Hammen Avatar answered Oct 19 '22 21:10

David Hammen