Generic const - a non-functional view
Steven Schveighoffer
schveiguy at yahoo.com
Wed Jun 25 06:37:30 PDT 2008
"Jason House" wrote
> Steven Schveighoffer wrote:
>> I would really like to hear people's opinions, especially Walter's.
>
> What I like:
> * Sticking to fundamental principles
> * The const!(A,B)(T) syntax looks quite clean
> * The ability for mixed const (AKA restricted mutability)
>
> What I don't like:
> * const!(~mutable)(T) syntax. While a mutable keyword may be kind of
> nice,
> the syntax is starting to get clunky and also become the only syntax
> for "not const"
Yes, it is clunky, but also hidden :) All you ever have to do is use
'mutable', 'lconst', and 'linvariant.' Compare it to mixins or templates.
import std.mutable;
class myclass
{
mutable int x;
int y;
}
void f(lconst(myclass) input)
{
input.y = 2; // error, input.y is const
input.x = 3; // ok.
}
> * No discussion of how to define const/invariant functions
I did leave this out. Since const!(T) is analogous to const, it would be
the same:
class myclass
{
lconst void f() { /* 'this' is lconst */}
void f2() lconst {/* same thing */}
}
> A lot of times, when I think about tail const/mixed const/mutable/..., I
> start thinking about arrays.
> AKA:
> T[] vs. array!(T)
> const(T)[] vs. array!(const(T)) vs. const!(element)(array!(T))
or const!(element)(T)[]
or
alias const!(element) eleconst;
eleconst(T)[]
-Steve
More information about the Digitalmars-d
mailing list