Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-05-17 14:18:31


Dave Harris wrote:
>
> In-Reply-To: <3CE51183.8A3C172_at_[hidden]>
> On Fri, 17 May 2002 16:19:47 +0200 Daniel Frey (daniel.frey_at_[hidden])
> wrote:
> > 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;
> > }
>
> This returns true if the distance is greater than that requested. Is that

The test-program I compiled with gcc 2.95.2 works as expected and does
returns false if the distance is greater than that requested. What
compiler/STL are you using? Here's the code:

#include <iostream>
#include <vector>
using namespace std;

template< typename Iterator >
bool is_distance( Iterator first,
                  const Iterator& last,
                  int distance )
{
   while( distance >= 0 && first != last ) {
      ++first;
      --distance;
   }
   
   return distance == 0;
}

int main()
{
   vector< int > v;
   
   v.push_back( 1 );
   v.push_back( 2 );
   v.push_back( 3 );
   v.push_back( 4 );
   v.push_back( 5 );
   v.push_back( 6 );

   cout << ( is_distance( v.begin(), v.end(), 5 ) ? "YES" : "NO" ) <<
endl;
   cout << ( is_distance( v.begin(), v.end(), 6 ) ? "YES" : "NO" ) <<
endl;
   cout << ( is_distance( v.begin(), v.end(), 7 ) ? "YES" : "NO" ) <<
endl;
   
   return 0;
}

The only difference is the second parameter type, but I doubt that this
is the problem...

Regards, Daniel

--
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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