Fully transitive const is not necessary
Leandro Lucarella
llucax at gmail.com
Fri Apr 4 09:37:21 PDT 2008
Steven Schveighoffer, el 4 de abril a las 09:24 me escribiste:
> class C
> {
> // this is like a struct passed as an argument to all methods, and is
> always mutable
> nonstate
> {
> int c;
> }
>
> // is passed an implicit nonstate pointer to the nonstate values
> int f(int x) const
> {
> return nonstate.c++;
> }
> }
Why don't you just do something like this:
static int[C] nonstate;
class C
{
// is passed an implicit nonstate pointer to the nonstate values
int f(int x) const
{
return nonstate[this] += 1;
}
}
If nonstate is not part of the object, why to put it in it? I this the
cache-problem is a very specific problem, which is OK to have a specific
solution. Even more, I find a lot more clear if the cache it's outside the
class, because is not part of it (if it's not part of the state of the
object, it's not part of the object at all!).
So C.f() is clearly not pure, but it's const, it doesn't change the state
of the object.
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Pack and get dressed
before your father hears us,
before all hell breaks loose.
More information about the Digitalmars-d
mailing list