Alexander Stepanov: STL and Its Design Principles

By: WalterCReel3rd

100   1   11053

Uploaded on 05/03/2012

Alexander Stepanov: STL and Its Design Principles. Talk presented at Adobe Systems Inc., January 30, 2002

Comments (2):

By anonymous    2017-09-20

To be able to write if (s.contains()), contains() has to return a bool (or a type convertible to bool, which is another story), like binary_search does.

The fundamental reason behind the design decision not to do it this way is that contains() which returns a bool would lose valuable information about where the element is in the collection. find() preserves and returns that information in the form of an iterator, therefore is a better choice for a generic library like STL. This has always been the guiding principle for Alex Stepanov, as he has often explained (for example, here).

As to the count() approach in general, although it's often an okay workaround, the problem with it is that it does more work than a contains() would have to do.

That is not to say that a bool contains() isn't a very nice-to-have or even necessary. A while ago we had a long discussion about this very same issue in the ISO C++ Standard - Future Proposals group.

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.