On Saturday, 30 March 2013 at 12:00:32 UTC, Namespace wrote:
As far as I studied the code, something like @ref isn't possible, because ref is already a keyword. Except as Pseudo-property. But this is a combination of '@' and 'ref' so that both, '@ref' and '@ ref' would be valid.
I still like the idea of '&A'.

I have to disagree with me here.
Thanks to this thread (http://forum.dlang.org/thread/ohjdraaizvwiczifw...@forum.dlang.org) I know now that after the '@' can be an unlimited number of white spaces. Hence my previous speculation that I would have implemented something wrong is wrong. So is something like '@ref' possible and already implemented, as you can see here: https://github.com/Dgame/dmd/tree/rvalue_property

I think this is probably the end result of my little journey. Any objections?

Quick example:

[code]
struct A {
public:
        ubyte id;
        
        this(ubyte id) {
                this.id = id;
        }
        
        this(this) {
                writeln("postblit of #", this.id);
        }
}

void foo(@ref A a) {
        writeln(":: id = ", a.id);
}

void foo1(@ref const A a) {
        writeln(":: id = ", a.id);
}

void foo2(@ref shared A a) {
        writeln(":: id = ", a.id);
}

void foo3(@ref immutable A a) {
        writeln(":: id = ", a.id);
}

// void foo4(@ref lazy A a) { /// Error: incompatible parameter storage classes
        // writeln(":: id = ", a.id);
// }

// void foo5(@ref ref A a) { /// Error: redundant storage class ref
        // writeln(":: id = ", a.id);
// }

// void foo6(@ref out A a) { /// Error: incompatible parameter storage classes
        // writeln(":: id = ", a.id);
// }

void bar(@ref int a) {
        writeln(a);
}

void quatz(T)(@ref T t) {
        static if (is(T == struct))
                writeln(t.id);
        else
                writeln(t);
}
[/code]

Reply via email to