help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: std::distance


From: Thomas Maeder
Subject: Re: std::distance
Date: Fri, 24 Mar 2006 18:39:03 +0100
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

Artus <artus@nomail.fr> writes:

> double tab[] = {0.6, 1.0, 3.0, 10.0, 20.0, 50., 1000.};
> std::vector<double> const myvec(tab, tab+sizeof(tab)/sizeof(double));
> /* ... */
> for (std::vector<double>::const_iterator it = myvec.begin();
> it!=myvec.end(); ++it) {
>      std::vector<double>::difference_type i = 0;
>      std::distance(myvec.begin(), it, i);
>      /* .. */
> }
>
> The compilation error message reads :
>
> error: no matching function for call to
> `distance(__gnu_cxx::__normal_iterator<const double*,
> std::vector<double, std::allocator<double> > >,
> __gnu_cxx::__normal_iterator<const double*, std::vector<double,
> std::allocator<double> > >&, ptrdiff_t&)'

std::distance() only takes two parameters. Does

std::vector<double>::difference_type dist(std::distance(myvec.begin(), it));

work?


> P.S. : I cannot use the version of std::distance with a return
> value, as it does not work under Sun CC5.3

I see. Then you are out of luck, because there is no other version in
Standard C++.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]