Boost logo

Boost Users :

From: Duane Murphy (duanemurphy_at_[hidden])
Date: 2003-04-29 10:24:10


--- At Tue, 29 Apr 2003 10:56:03 +0000, John Harris wrote:

>--- In Boost-Users_at_[hidden], "Duane Murphy" <duanemurphy_at_m...>
>wrote:
>> --- At Fri, 25 Apr 2003 17:01:56 -0400, Vincent LaBella wrote:
>> >sequence, so I tried
>> ><snip>
>> >last = tok.begin();
>> >advance(last,tok.size()-1); // error size() not defined.
><snip>
>> Implementation left as an excercise. (Is there a standard algorithm
>that
>> might fit well besides for_each()?)
>
>how about: std::advance(first, std::distance(first,last)-1) ?
>
>The only requirement for distance() is that iterators be input
>iterators, which tokenizer's are.

This is an interesting solution. The downside is that the iterator would
get advanced twice. I believe the implementation for distance for a
forward iterator is to walk the iterator and count the distance. Then
advance is going to do the same. This is efficient to type, but
inefficient to run.

 ...Duane


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net