Another design decision that baffled me. Checking if an element is in a set is the entire purpose of a set! Until C++20 I had to write stuff like s.find(x) != s.end()
or the nicer s.count()
cast as a bool that's almost as good as contains()
but somewhat obscures the intent (and runs in O(n) for multisets?). Even if the standard library containers were designed around iterators, count()
has existed from the beginning.
The P0458 proposal to add contains is obvious, but there must've been some kind of argument for leaving it out originally and then leaving it out every time it was brought up. Was there some kind of design philosophy change in C++20?