Boost logo

Boost :

Subject: Re: [boost] [iterator][range] BoostIteratorTraversalConcepts-aware boost::advance/distance
From: Michel Morin (mimomorin_at_[hidden])
Date: 2017-06-29 00:35:03


Hi Andrzej,

Andrzej Krzemienski wrote:
>> IMHO, Boost.Iterator should provide BoostIteratorTraversalConcepts-aware
>> `boost::advance` and `boost::distance` to avoid the inefficiencies.
>
>
> Not just inefficiencies. Using `prev()` may simply cause UB. See here:
> https://akrzemi1.wordpress.com/2017/01/02/not-detecting-bugs/

Yes, and ditto for `std::advance` with negative numbers.
Your blog is helpful; thank you for writing C++ blog!

>> However,
>> neither of them are implemented. (Boost.Range has `boost::distance` for
>> ranges, but it just calls `std::distance`.)
>>
>> I'm attaching files that implement `boost::advance` and `boost::distance`.
>> Would these functions be useful additions?
>>
>
> They are necessary for Boost to be consistent. But I think this means
> coupling two libraries.

Do you mean coupling of Boost.Iterator and Boost.Range? I think that would
be fine, since Boost.Range already couples with Boost.Iterator.
Boost.Range's `boost::distance` should call Boost.Iterator's `boost::distance`.

Regards,
Michel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk