Message from discussion
iterator conversion
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news.cse.psu.edu!uwm.edu!rpi!not-for-mail
From: Andy Sawyer <an...@evo6.com>
Newsgroups: comp.lang.c++.moderated,comp.lang.c++
Subject: Re: iterator conversion
Date: 5 Oct 2002 06:00:09 -0400
Organization: Office of the Punmaster General
Lines: 64
Sender: cppm...@netlab.cs.rpi.edu
Approved: francis.modera...@robinton.demon.co.uk
Message-ID: <8z1dsmkl.fsf@ender.evo6.com>
References: <2f0c7ab9.0210040610.7232fce8@posting.google.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
X-Original-Date: Sat, 05 Oct 2002 01:24:14 GMT
X-Submission-Address: c++-sub...@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
iQBVAwUAPZ64JkHMCo9UcraBAQEbxQH9HUYdyuudAROyYNivL3am91lK8hbx8wvK
/U92k1TuNJ67zyw2ckgNVT/ds5m0lAtKSMFe99Sc5Mp/TfrpwLsRXg==
=EpQb
nur...@ematic.com (Alexis) writes:
> Hi guys,
>
> I am trying to create class that wraps a STL container and adds more
> high level features that are specific to my application. And I need to
> provide operators that behave in a similar way as begin() and end(),
> except that the position returned is different. For instance, here is
> one of them.
>
> " iterator InputLayerEnd()
> {
> ContainerDistance distance = nbNeuronPerLayer_[InputLayer] + 1;
> return advance(container_.begin(), distance);
> }"
>
The correct form of std::advance is:
template <class InputIterator, class Distance>
void advance(InputIterator& i, Distance n);
So what you probably want is:
iterator InputLayerEnd()
{
ContainerDistance distance = nbNeuronPerLayer_[InputLayer] + 1;
iterator iter = container_.begin();
advance( iter, distance );
return iter;
}
> Nothing fancy, I first do some internal computation to figure out
> where the real position is, and then use advance to obtain an iterator
> pointing to it. My problem is that the compiler does not allow me to
> do this, because of a conversion problem. And I do not understand why.
> Here is the error
>
> "mlp.hpp:117: could not convert `std::list<_Tp, _Alloc>::begin() [with
> _Tp =
> MlpNeuron<float>, _Alloc = std::allocator<MlpNeuron<float> >]()' to
> `
> std::_List_iterator<MlpNeuron<float>, MlpNeuron<float>&,
> MlpNeuron<float>*>&
> '"
>
This is odd - I'd take a wild guess that your STL implementation has a
non-standard signature for advance, like:
template <class InputIterator, class Distance>
InputIterator advance(InputIterator& i, Distance n);
Regards,
Andy S.
--
"Light thinks it travels faster than anything but it is wrong. No matter
how fast light travels it finds the darkness has always got there first,
and is waiting for it." -- Terry Pratchett, Reaper Man
[ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]