Opened 14 years ago

Closed 14 years ago

#274 closed discussion (invalid)

end() of Iterator

Reported by: Peter Owned by: Markus Ringnér
Priority: critical Milestone: yat 0.4
Component: classifier Version: trunk
Keywords: Cc:

Description

How should end() of Iterator behave? At time being it is implemented as index_=container_.size().

But my concern is what should happen if one try to iterate with the end, for example:

 if (vec.begin()+10!=vec.end())
   cout << "tjoho\n";

When should that statement be true? With current implementation it is equivalent to if (vec.size()!=10) but perhaps one expects if (vec.size()<10).

Change History (2)

comment:1 in reply to:  description Changed 14 years ago by Jari Häkkinen

Replying to peter:

How should end() of Iterator behave? At time being it is implemented as index_=container_.size().

But my concern is what should happen if one try to iterate with the end, for example:

 if (vec.begin()+10!=vec.end())
   cout << "tjoho\n";

When should that statement be true? With current implementation it is equivalent to if (vec.size()!=10) but perhaps one expects if (vec.size()<10).

No, the only(?) time the statement should be not true is when vec.begin()+10 == vec.end(). It is analogous to iterating a std::vector:

std::vector<int> i;
...
for (std::vector<int>::iterator x=i.begin() ; x!=i.end() ; ++x)
  statement;

where the loop never stops if x goes past i.end() with a stupid statement pushing x beyond i.end().

comment:2 Changed 14 years ago by Peter

Resolution: invalid
Status: newclosed

I close this ticket because the current implementation seems to be fine.

Note: See TracTickets for help on using tickets.