
----- Mensaje original ----- De: Ovanes Markarian <om_boost@keywallet.com> Fecha: Martes, Agosto 21, 2007 1:27 pm Asunto: Re: [Boost-users] [boost::multi-index] improvement suggestion Para: boost-users@lists.boost.org
Joaquin,
thanks for your reply. I have to think about your suggestions. Some ideaswhich come up to my mind now are: 1. Locator is clearly a better choice, but not always. In some use cases you might find a range if a container allows multi-indexed values. In this caseone would need to make second search to find subsequent values??? Or miss them at all...
I take you meant "duplicate values" rather than "multi-indexed values", right? If so, yes I agree with you a range is the proper object to return, but you'd have to use equal_range instead of find.
2. In the example with: boost::iterator_range<std::set <std::string>::const_iterator> r= find_range(...);
The class value_retrieval contains a result_type which provides the shortcut to iterator_range<...>
Correct, this'd make the syntax terser.
3. My idea in using iterator range relies on fact that one can retrieve a valid or invalid range and operate on it within one search. Your idea with there_exists requires a second search to retrieve the value. Since a typical use case would be:
if(there_exists(some_container, "some_key")) some_value = *some_container.find("some_key");
and that is not so efficient as:
iter_range range = find_range(some_container, "some_key"); if(range) some_value = range.front();
OK, then a locator seems to me to provide a nicer syntax in one single call than your first approach based on ranges. My point is only that your approach has a nice interface for checking if the value exists but not so much for accessing the actual value.
I will think about other suggestions and mail them later in ;)
Thank you for using Boost.MultiIndex and thinking up ways to improve the experience it provides. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo