|
Boost Users : |
Subject: Re: [Boost-users] iterator_facade and distance()
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-04-16 19:54:21
At Sun, 17 Apr 2011 08:43:00 +0900,
Andrej van der Zee wrote:
>
> Hi Dave,
>
> Thanks for your email.
>
> >
> > Not unless yours is a random access iterator. Â Is it?
> >
>
> Its a forward iterator. Changing it to a random access iterator solves
> it indeed.
>
> This is my first iterator that I am writing, but why is it not
> possible to implement a custom distance method for forward iterators?
The implementation of std::distance only has the iterator category to
go on when deciding whether to move by many steps or by one jump.
There isn't any other information it can use.
> Am I doing something conceptually wrong?
Could be. If you can move your iterator by N steps in one jump, maybe
it should be a random access iterator.
> Or should I specialize the
> std::distance() function?
You could specialize that function for specific iterator types.
There's no partial specialization of function templates, and you're
not allowed to add an overload to namespace std.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
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