|
Boost : |
From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2024-12-17 16:20:45
> Working with ranges is an interesting idea, and comparisons to
> std::ranges::find might encounter obstacles. I presume that the OP was
> talking about returning an optional value given the key. This presumes
> an associative container.
Why limit this to associative containers? A generic version can search a
std::vector as well as a std::set or boost::unordered_map
You just need to dispatch to either container.find or fallback to std::find
> I am not too familiar with ranges, is there
> an "associative range" concept? I do like the default value idea
> though, thanks for that :)
Having the optional return type you get the default for free:
find(...).value_or()
I'm not too sure about supporting ranges: The hypothetical find function
would return an optional reference.
So we have the footgun of getting dangling references already when
someones does `find(build_map(), key)`
We can avoid that by deleting the overload for rvalues but i guess for
ranges we might not be able to easily detect an underlying temporary.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk