Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-05-17 13:28:31


> How about:
>
> template< typename Iterator >
> bool is_distance( Iterator first,
> call_traits< Iterator >::param_type last, // Add
> const?
> int distance ) // Should have a default?
> {
> while( distance >= 0 && first != last ) {
> ++first;
> --distance;
> }
>
> return distance == 0;
> }
>
How is this better than:

if ( std::distance(seq.begin(),seq.end()) == n ) ...

IOW, why is "is_single_element", or "has_n_elements" better than the idiom
above?

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk