3 ms·
That's just objectively untrue. C++ sets have always supported membership testing. bool set_contains_x = set.find(x) != set.end();
by Calavar 3y ago
That's just objectively untrue. C++ sets have always supported membership testing.
bool set_contains_x = set.find(x) != set.end();
- Aardwolf 3y agoI know that, but that's a rather elaborate way of doing the main thing sets do, and you have to repeat the name of the set twice. Fortunately C++20 added set.contains(x). Of course set.count(x) also already existed but some would prefer set.find(x) != set.end() anyway for <reasons>, and it's the fault of the language's design to cause such opinions in the first place imho.
- qarl 3y agoI hate to be pedantic, but since you started it: That is not a contains() function. That is a search followed by a test for not not-found.
- Calavar 3y agoThat's a valid distinction for a vector or a list. For a set, contains and search are one and the same.
- qarl 3y agoNo, they are not the same thing. They are logically equivalent, which is not the same thing as same thing. 1+3 is logically equivalent to 4, but they are not the same. As just one example, the former contains an operation.