Reputation: 9435
Well is it possible/"good" to overload std::find
for custom classes in objects? And then without overloading the equality operators. Say a container stores (smart) pointers to it's actual data, I really am not interested in the data layout or storage mode, I just want to find a certain data member....
Is it legal, "moral", to o this? If say I have a std::vector<std::shared_ptr<myClass> >
- or "even" a user defined container? Or should I always rely on std::find_if
for cases like these?
Upvotes: 0
Views: 462
Reputation: 227420
The idiomatic solution would be to use std::find_if and give it a suitable predicate.
This keeps the code you have to write and maintain to a minimum, and decouples you from the specific container type.
Upvotes: 5