|
Boost : |
Subject: Re: [boost] On Iteration
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2009-11-11 20:17:10
2009/11/11 Christian Holmquist <c.holmquist_at_[hidden]>:
> How would the following example from the SGI STL doc be written in, say, D's
> standard library (I did search the D documentation, but couldn't find the
> answer).
>
> Â Â std::vector<int> v;
> Â Â v.push_back(...);
> Â Â v.erase(v.begin(), std::find(v.begin(), v.end(), X));
>
That's my biggest complaint with ranges so far. Similar problems
exist if you want to get the range of elements before the pivot out of
a partition.
For this particular case, the usual answer is that you should be using
a sentinel-terminated range instead of the find, something like this:
auto before_part = before(v.all(), X);
But as you point out, it's unreasonable for vector to have to know
about a before_range to be able to handle that, so near as I can tell
you're stuck with using slice:
auto before_part = v.all().slice(0, v.size()-find(v.all(), X).size());
Which is quite ugly and error-prone, not to mention the obvious
complaint that it requires a random-access, finite range for something
that's doable with just a forward iterator.
I've been musing about whether something iterator-like, but opaque, Ã
la fgetpos/fsetpos, would be a feasible solution, but haven't worked
out the details.
Bright ideas welcome,
~ Scott McMurray
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk