On 2010-11-29 11:19:29 -0500, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> said:
Syntax is the main issue in implementing this feature. Due to the
implicit nature of reference semantics for classes, there was no syntax
to distinguish between the head and the tail when qualifying.
FWIW I just thought of this syntax. It might work but it's not intuitive:
const()C tailConst;
I proposed the following a while ago. First allow the class reference
to (optionally) be made explicit:
C a; // mutable reference to mutable class
C ref b; // mutable reference to mutable class
And now you can apply tail-const to it:
const(C)ref c; // mutable reference to const class
const(C ref) d; // const reference to const class
const(C) e; // const reference to const class
I think it's better.
Ultimately I believe we need to make Rebindable palatable. That would
have the nice side effect of enabling other proxy types.
The biggest problem I see is with generic programming. Say I pass
Rebindable!(const C) as a template argument, then the template wants to
make it const: should it become const(Rebindable!(const C)), or will
this be resolved to const(C)?
You don't have this problem with pointers: const(const(int)*) is the
same type as const(int*). If 'const' was a template, you could
specialize it to do the same for Rebindable. But 'const' is a language
thing, and it seems utterly inappropriate to make const aware of
Rebindable so that const(Rebindable!...)) would drop the Rebindable,
and thus you get the above silliness.
I'm all for making proxy types work better, but it'll always feel
patchy in this case.
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/