
On 2 June 2011 12:57, Denis Shevchenko <for.dshevchenko@gmail.com> wrote:
What's the best way to get this wrapper into Boost?
Somebody? Please?
Olaf, the point is not that the library is useful for YOU, but rather whether it useful for OTHERS programmers. This is the criterion for inclusion library in the Boost.
- Denis
We've a function like this among our quite extensive set of useful stl wrapper functions. While I agree this one is useful, I think most organizations are better off collecting their own set of utilities that suits their common use cases perfectly. Writing a std::map::find wrapper that aim to suit everyone is opening a can of worms, IMHO. Personally, I'd like to see a 'Boost.Algorithm.Find' package, that short and concisely can capture the myriads of different ways to express find, and that works on associative and sequence containers of tuples. Maybe something like this. std::vector<int> v; boost::algorithm::find_optional<0>(v, 3) std::vector<std::pair<int, float> > v; boost::algorithm::find_optional<0>(v, 3) boost::algorithm::find_optional<1>(m, 3.0) std::map<int, float> m; boost::algorithm::find_optional<0>(m, 3) -> map::find(...) boost::algorithm::find_optional<1>(m, 3.0) -> std::find(...) The compile time constant indicates which tuple element to find (fusion compatible, say). Return value is always optional<Container::value_type&>. (and const versions thereof) The algorithm is responsible for using the best implementation of find, i.e. avoid going trough std::find() if the container is associative and the element index is 0. If element index is 1, it needs to use std::find also for associative, Unless it's boost::bimap.. =) Probably not worth the effort. - Christian