[Solved] Explanation of the names of C++ std lib methods [closed]


  1. vector: There are vectors in functional languages too, like this package
  2. unordered_set – Unordered/ordered refers to the underlying implementation; how the elements are actually stored.
  3. vector.cendcend is a constant iterator pointing to the end. Constant iterators don’t let you modify the value pointed to by the iterator.
  4. emplace – Emplace is like insert except it creates the object “in-place”; you pass emplace the parameters you would pass to the object’s constructor.
  5. push_back – This is to maintain a uniform interface. Some containers like std::list let you push_front
  6. Why does empty() return a boolean? Shouldn’t it be isEmpty()?: Should it? Says who? You’re used to Python/Scala/Haskell but that’s hardly the one true way.
  7. Also, the .begin() and .end() seems inconsistent. begin() is a verb while end() is a noun in this context. begin denotes to start something whereas it simply returns a pointer to start. Shouldn’t the method be called either start which is a noun and goes well with “end” or beginning atleast instead of begin: I suppose. This seems like a petty gripe. It’s just the way it is.
  8. Why does list.unique not return a set? It seems weird it not only modifies the data structure (coming from a functional world, it seems really weird to mutate data as side effects) and it is doubly weird here since C++ already has sets. Am I understanding unique wrong??: A lot of things will be weird if you carry that mindset of no side-effects into C++. The same open mind that let you learn Python/Scala/Haskell should be applied to C++ if you are serious about learning it. list.unique is more like Ruby’s Array#uniq. From the documentation:

Notice that an element is only removed from the list container if it compares equal to the element immediately preceding it. Thus, this function is especially useful for sorted lists.

As described, returning a set would lose information because it wouldn’t preserve duplicates in the case where they are not consecutive.

Like I said, if you’re serious about learning C++ you’ll have to deal with some of these language/library design decisions. Many of these points seem like petty gripes to me. Some of these are “just the way it is”. Some things in C++ are straight up crazy, but if you’re serious about C++ what are you going to do? Indeed, Haskell for example seems to have a more straightforward design that “naturally follows,” but that’s a different kind of language. Hopefully you can get over this.

solved Explanation of the names of C++ std lib methods [closed]