Re: [hub] on the specialized iteration over elements
Jean-Louis Leroy via Boost <[email protected]>
| Newsgroups | gmane.comp.lib.boost.devel |
|---|---|
| Message-ID | <CAKPZfxm2reuAUK9ffds_g5y_uVdhEAA4O=Dxhq1n5EuugKsR_w@mail.gmail.com> |
It seems to me that 'visit' is useful and legal only in combination
with 'operator++',
'operator--' and the likes of 'std::next', 'std::prev',
'std::advance', etc. For example:
int main() {
boost::container::hub<int> h {1, 3, 5, 7, 9};
auto first = h.begin();
auto middle = std::next(first, h.size() / 2);
auto last = h.end();
h.visit(first, middle, [](int i){
std::print("{} ", i);
});
std::print(" | ");
h.visit(middle, last, [](int i){
std::print("{} ", i);
});
}
(https://godbolt.org/z/1e5E413r8)
Important use cases are divide-and-conquer algorithms and parallelization.
>From here, two things.
If 'visit' is faster than just "ranging over", it probably (?) means
that we need
'hub::advance' etc as well.
But then an integer displacement is always involved, be it 1 or -1.
Doesn't it suggest
that 'visit' should take offsets, not iterators? That would take care
of Andrzej's
concern. And there is no need for public 'advance' etc members.
_______________________________________________
Boost mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/XU55RBYVSU5HLCHM5WZP6YHHPYSJX7UG/