|
Boost Users : |
Subject: Re: [Boost-users] any_range vs. canonical form - what is the latter?
From: Neil Groves (neil_at_[hidden])
Date: 2011-04-09 12:45:55
On Sat, Apr 9, 2011 at 4:36 PM, Steven Watanabe <watanabesj_at_[hidden]>wrote:
> AMDG
>
>
> On 04/08/2011 11:46 PM, John Funnell wrote:
>
>> Boost's any_range documentation says the following:
>>
>> "Despite the underlying any_iterator being the fastest available
>> implementation, the performance overhead of any_range is still
>> appreciable due to the cost of virtual function calls required to
>> implement increment, decrement, advance, equal etc. Frequently a
>> better design choice is to convert to a canonical form."
>>
>> What does the author mean by a "canonical form"? Can someone give an
>> example?
>>
>>
> 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. The use of any_range may also make
sense where the number of passes over the range are small, but the memory
size of the underlying container is very large.
In many cases, the performance overhead will not matter. I wanted to ensure
that I did not mislead anyone into the widespread adoption of any_range
usage. I believe that the valid usages for this class are few, but sometimes
it is *exactly* the correct design choice. I shall improve the documentation
with some additional clarification and examples in due course.
Thank you for your great question.
Regards,
Neil Groves
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