Re:Idiomatic Python [video]
by benhoyt on Wednesday March 13, 2013 @04:14PM
(#5370837)
I'm not sure why "find" or "contains" isn't a member function of STL container types, but there is the std::find() function:
Edit: I admit this is terrible API design. When you want the v.begin()/v.end() combination 90% of the time, why not at least have a std::find() overload that does that for you? Or simply add "std::contains(v, x) -> bool"? You can write your own version of that, of course, but... my take-home point: API design is very important.
[ Parent
| on HN ]
Providing container operations as functions in <algorithm> operating on iterators means that someone implementing a new container with iterators immediately has a wealth of functionality available with no extra effort.
Also, containers that are most well suited to membership searches (std::set and std::multiset) do include find(Key const& key) as a member.