Possible Time Series Bug

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible Time Series Bug

marco.tarenghi@libero.it
Hi all,
I think I've found a bug in the TimeSeries class.
There it is implemented the [] operator in two different ways, I think the second one is wrong: more in detail, according to me the operator returning a reference contains an error in the "if" condition

T& operator[](const Date& d) {
    if (values_.find(d) != values_.end())
        values_[d] = Null<T>();
        return values_[d];
    }
}

it should be "==" and not "!=", otherwise in the case it finds the date it returns a Null<T> value.
Probably it has been mis-specified because it replicates the implementation of the alternative [] operator, but in that case the output is different and the operator works fine.

By the way, if I instantiate a TimeSeries object and then I use the [] operator, how does the object know which is implementation to choose?

Thanks,
Marco


___________________________________________________________________
Prestiti da 15 istituti. Tan dal 5,90% per richieste entro il 15 Settembre. Servizio gratuito.
http://click.libero.it/mutuionline3




Reply | Threaded
Open this post in threaded view
|

Re: Possible Time Series Bug

因藤英城
Hi, Marco.

I argee your opinion. Probabary it should be
 if (values_.find(d) == values._end())
    values_[d] = Null<T>();
 return values_[d];

> By the way, if I instantiate a TimeSeries object and then I use the [] operator,
> how does the object know which is implementation to choose?

Do you mean which method is invoked, when you call operator [](const
Date&) method?
I think operator [](const Date&) const method should be invoked,
if it is called from constness object, otherwise operator [](const Date&)
is invoked.

I'm afraid that this does not become answer for your question.

Thanks,
indou.


------
 Name:因藤 英城<Hideki Indou>
 mailto :[hidden email]



Reply | Threaded
Open this post in threaded view
|

Re: Possible Time Series Bug

Luigi Ballabio
In reply to this post by marco.tarenghi@libero.it

On 08/30/2006 11:02:57 AM, [hidden email] wrote:
> I think I've found a bug in the TimeSeries class.
> There it is implemented the [] operator in two different ways, I  
> think the second one is wrong.

Right. I've fixed it in CVS. Thanks for pointing it out.


> By the way, if I instantiate a TimeSeries object and then I use the  
> [] operator, how does the object know which is implementation to  
> choose?

It's as Indou said. If the object is const, the const version is  
called; otherwise, the non-const version kicks in.

Luigi


----------------------------------------

Humphrey's Requirements Uncertainty Principle:
        For a new software system, the requirements will not be
        completely known until after the users have used it.