
----- Mensaje original ----- De: Matias Capeletto <matias.capeletto@gmail.com> Fecha: Miércoles, Mayo 23, 2007 11:20 pm Asunto: [boost] [bimap][multi_index][range] sub_range vs std::pair<iter, iter> Para: "boost@lists.boost.org" <boost@lists.boost.org>
Hi,
Boost.MultiIndex and Boost.Bimap implements a function named range. It is designed to integrate well with the new Boost.Range framework.
The actual signature is:
template< class LowerBound, class UpperBound > std::pair<iterator,iterator> range( LowerBound lower, UpperBound upper); template< class LowerBound, class UpperBound > std::pair<const_iterator, const_iterator> range(LowerBound lower, UpperBound upper) const;
In bimap docs it is stated that the way to use it is:
typedef bimap<string,int> bm_type; bm_type bm; //... std::pair<bm_type::left_iterator, bm_type::left_iterator>r = bm.left.range(...,...);
I want to know if this is the best approach. Boost.Range defines two range classes (iterator_range and sub_range) http://www.boost.org/libs/range/doc/utility_class.html It is said that they are better abstraction for ranges that std::pair<iter,iter>
1) Do you think that the range functions should return a sub_range<map_type>instead of a std::pair<iter,iter>? [...]
IMHO, no, so as to avoid unasked for dependencies between libraries --both at a conceptual and #include level. Moreover, one can always convert the std::pair to a range very easily, although this conversion would be much simpler if iterator_range and sub_range provided ctors taking std::pairs of iterators --Thorsten, would you consider adding this a good idea?
2) In any case do you think that including typedef for the returned range type will make code more readable? The idea is to define:
typedef -range_type- sub_range; // the name can be different typedef -const_range_type- const_sub_range;
So the user code will look like this:
typedef bimap<string,int> bm_type; bm_type bm; //... bm_type::left_sub_range r = bm.left.range(...,...);
I am not sure. On one hand, the syntax above is obviously more concise, but on the other hand a casual reader would have to look up what sub_range is to fully understand the code, whereas the std::pair is self explanatory and moreover it's honored by the tradition of equal_range(). Just my 2c, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo