Boost logo

Boost Users :

Subject: Re: [Boost-users] any_range vs. “canonical form” - what is the latter?
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2011-04-09 14:36:56


Den 09-04-2011 18:45, Neil Groves skrev:
> On Sat, Apr 9, 2011 at 4:36 PM, Steven Watanabe <watanabesj_at_[hidden]

>
> For example, copying the range into a vector.
>
>
> Yes, this is exactly the alternative design that I had in mind when
> writing the documentation. The overhead of iterating over an any_range
> is quite considerable, and often compares poorly with copying a concrete
> result-type into a container such as a vector. However, this is not
> always the case and some of the users of Boost.Range have desired the
> ability to implement algorithms that operate upon any_range instances.
> This is sometimes desirable to allow, for example, exposure of
> algorithms from a shared library that supports various containers.

Two questions:

A. would it not be more efficient to store only
a range object instead of two iterators as this
leads to each iterator begin potentially heap-allocated.
(e.g. use boost::iterator_range<I> internally)

B. would it not make sense to remove a whole bunch
of those template arguments to any_range? Why can't I just say

void foo( const any_range<int>& rng )
{
     switch( rng.category() )
     {
     case boost::ranges::consequtive: ...; break;
     case boost::ranges::randome_access: ...; break;
     // etc
     }
}

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net