const and immutable objects
Graham St Jack
Graham.StJack at internode.on.net
Sun Aug 30 21:36:01 PDT 2009
On Sun, 30 Aug 2009 21:28:18 -0400, Jeremie Pelletier wrote:
> I agree that D lacks a mechanism to separate the object from it's
> reference. Maybe syntax like the following could be used to apply the
> storage class to the object value, and not the reference value:
>
> class Foo;
> void bar(in Foo& foo) {}
>
> It's quite ugly and C-like, but that's the first thing that came to
> mind. The reference value is unique to the current method and shouldn't
> share the same storage qualifiers as it's referenced memory.
I think the time for pining over this particular syntax feature of D is
over - as nice as it would be to be able to fix the problem in the
language, it would be too disruptive right now. What we need is something
in phobos that works around the problem, and Rebindable isn't suitable as
it stands because:
* It presents different interfaces for different kinds of wrapped types.
* It doesn't let you access the wrapped object except via opDot.
My suggested workaround is perhaps a bit rough, but it does work. I would
like to hear from anyone who is using const and immutable objects in D2
who has something better, or has suggestions to improve my code.
More information about the Digitalmars-d
mailing list