On Friday 09 August 2002 11:59 am, Angus Leeming wrote:
> On Friday 09 August 2002 12:23 pm, Andre Poenitz wrote:
> > On Fri, Aug 09, 2002 at 11:36:13AM +0100, Angus Leeming wrote:
> > > and can therefore be simplified to
> > >
> > > void Counters::copy(Counters & from, Counters & to)
> > > {
> > > CounterList::iterator it = counterList.begin();
> > > CounterList::iterator end = counterList.end();
> > > for (; it != end; ++it) {
> > > to.set(it->first, from.value(it->first));
> > > }
> > > }
> >
> > Does this change 'from'?
>
> int Counters::value(string const & ctr) const
> {
> CounterList::const_iterator cit = counterList.find(ctr);
> if (cit == counterList.end()) {
> lyxerr << "value: Counter does not exist: " << ctr << endl;
> return 0;
> }
> return cit->second.value();
> }
>
> No.
But you are right to notice that the semantics of this method are very
confusing.
1. It's a member of Counters, but does not set *this.
Is this what is meant:
void Counters::copy(Counters const & from)
{
CounterList::iterator it = counterList.begin();
CounterList::iterator end = counterList.end();
for (; it != end; ++it) {
it->set(from.value(it->first));
}
}
?
2. Alternatively, it could be a non-member function
void Counters::copy(Counters const & from, Counters & to)
{
CounterList::iterator it = to.counterList.begin();
CounterList::iterator end = to.counterList.end();
for (; it != end; ++it) {
it->set(from.value(it->first));
}
}
As it is, I have no idea what it is meant to be doing, but it ain't doing it!
Angus
But is Counters::copy doing what it's meant to be doing?
Why is it a member variable that resets to