|
Boost : |
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2019-08-12 13:19:21
Hans Dembinski wrote:
> compare vs. distance_to
This reminds me of an issue that I've found with the existing
iterator_facade: sometimes I can magnitude-compare the iterators,
but not report a distance.
For example, a simple filter iterator can quickly tell whether A is
before or after B by comparing the underlying iterators, but it cannot
find the distance without applying its filter predicate to all the
intermediate elements.
Currently, operator< etc. in the facade are implemented by calling
the user's distance_to which is inefficient in this case. Your change
of name to compare made me wonder if it is now expected only to return
-1/0/+1, but that doesn't seem to be the case.
The other thing that I've found tedious to do with the current
iterator_facade is implementing both iterator and const_iterator.
The pattern I tend to use is:
template <bool is_const>
class iterator_base: public boost::iterator_facade< ......... >
......
using iterator = iterator_base<false>;
using const_iterator = iterator_base<true>;
I don't know if there is anything that iterator_facade could do to
make this easier.
Regards, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk