Boost.Range

FAQ

  1. Why is there no difference between iterator_of<C>::type and const_iterator_of<C>::type for std::pair<iterator, iterator>.
  2. In general it is not possible nor desirable to find a corresponding const_iterator. When it is possible to come up with one, the client might choose to construct a std::pair<const_iterator,const_iterator> object.

    Note that an iterator_range is somewhat more convenient than a pair.

  3. Why is there not supplied more types or more functions?

    The library have been kept small because its current interface will serve most purposes. If and when a genuine need arises for more functionality, it can be implemented.

  4. How should I implement generic algorithms for ranges?

    One should always start with a generic algorithm that takes two iterators (or more) as input. Then use Boost.Range to build handier versions on top of the iterator based algorithm. Please notice that once the range version of the algorithm is done, it makes sense not to expose the iterator version in the public interface.

  5. Why is there no Incrementable Range concept?

    Even though we speak of incrementable iterators, it would not make much sense for ranges; for example, we cannot determine the size and emptiness of a range since we cannot even compare its iterators.

  6. Should I use qualified syntax, for example
    boost::begin( r ); 
    
    instead of
    using namespace boost;
    begin( r )
    when calling functions in this library? If so, can I still rely on argument dependent lookup (ADL) to kick in?

    The answer to the first question is that "it's up to you". The answer to the second question is Yes. Normally qualified syntax disables ADL, but the functions are implemented in a special manner that preserves ADL properties. The trick was explained by Daniel Frey on comp.lang.std.c++ in the thread "Whence Swap" and it is best explained by some code:

    namespace boost
    {
        namespace range_detail                
        {
            template< class T >            
            typename iterator_of<T>:type begin( T& r )
            { /* normal implementation */ }
        }   
                    
        template< class T >                
        typename iterator_of<T>::type begin( T& r )
        {
            //        
            // Create ADL hook
            //        
            using range_detail::begin;                    
            return begin( r );                
        }
    }                    
    
    Cool indeed!


(C) Copyright Thorsten Ottosen 2003-2004