
On Tue, 17 Dec 2024 at 15:51, Vinnie Falco via Boost
On Tue, Dec 17, 2024 at 7:21 AM Andrey Semashev via Boost < boost@lists.boost.org> wrote:
I don't see why it should be limited to unordered containers.
I meant associative, not just unordered. The choices are:
It doesn't even need to be limited to containers. I think it generalizes to ranges. Isn't the free function along the lines of auto find_or(Rng&& rng, Key&& key, Default&& default) ? This works for all containers that allow the default to be something other than nullopt, which is very useful in many contexts. Where there are associative containers it can delegate to the optimal container implementation, but it can fall back to the general logic of std::ranges::find. A production version would, I assume, have the projection and other usual range idioms.
1. Add a member function to uncountably many existing and future associative containers by adding a member function
2. Write a single, separate free function template which works for all existing and future associative containers
The free function is clearly the objectively superior solution. This is fact and is preferred over opinions no matter the authority. The member function approach is objectively inferior, and has no compensatory advantage.
If we include all associative containers instead of just the unordered ones, the case for a free function is even stronger as the free function will work with more types. And the member function would require considerably more work (since there are even more containers which have to change).
Thanks
Neil Groves