Walter is right about transitive readonly - here's the alternative
Bill Baxter
dnewsgroup at billbaxter.com
Thu Sep 13 17:26:37 PDT 2007
Sean Kelly wrote:
> Frits van Bommel wrote:
>> Sean Kelly wrote:
>>> Though the lack of a dot operator overload may complicate the syntax
>>> a tad.
>>
>> Isn't that what 'alias this' would be for?
>
> Hrm... so something like this?
>
> struct SmartPtr( T ) {
> T* val;
> static if( is( T == class ) ||
> is( T == struct ) )
> alias val this;
>
> void opAssign( T* v ) {
> val = v;
> }
> }
>
> struct S {
> void foo() {}
> }
>
> SmartPtr!(S) p = new S;
> p.foo();
>
>
> Seems like it would work, huh :-) I hadn't really thought about 'alias
> this' in this context.
That is interesting. But if inheritance is such a great way to
implement smart pointers, then why isn't it regularly used to implement
smart pointers in C++?
oh wait... you can't inherit from a pointer in C++.
Or dynamically change your base object.
With copy constructors and destructors this could be a very slick way to
do smart pointers. Nice!
--bb
More information about the Digitalmars-d
mailing list