Boost logo

Geometry :

Subject: [ggl] pre-/post-increment op on iterators
From: Barend Gehrels (Barend.Gehrels)
Date: 2009-04-28 10:08:46

>> A related question, I've created some iterators recently and it would
>> be convenient to have an interator on a vector which has a segment as
>> its valuetype. Didn't work it out and don't know if it is possible at
>> all, do you think it makes sense here?
> I'm not sure I can grasp the idea.
> Perhaps you could illustrate your idea with a snippet of code?
> I can see vector that has a segment as its value_type as
> simple as vector<segment>, but it is not what you're thinking of,
> I presume.
OK, let's try, it should look like something like this:

vector<point_2d> line;
// ... file this line somehow
ggl::segment_iterator<vector<point_2d>::const_iterator> it(line); //
creates iterator which should iterator over the whole line
ggl::segment_iterator<vector<point_2d>::const_iterator> end(line.end());
// indicates the end
while(it != end)
    ggl::segment<const point_2d> segment = *it;
    std::cout << length(segment) << std::endl;

So operator * returns a segment, valuetype should be a segment-type (can
be specified as template par), operator-> should work on a segment, etc.
It would be instead of having two iterators, I've often prev and it,
where prev=it++;

Regards, Barend

Geometry list run by mateusz at