how to compose delegate type

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sat Dec 7 16:43:35 PST 2013


On Saturday, 7 December 2013 at 23:02:18 UTC, Ellery Newcomer 
wrote:
> On Saturday, 7 December 2013 at 19:36:50 UTC, Jesse Phillips 
> wrote:
>>
>> This declaration doesn't make sense to me:
>>
>>    string a() immutable {
>>        return " 1";
>>    }
>
> http://dlang.org/class.html#member-functions

That isn't really the type of a delegate though. Outside of a 
class that usage has no meaning or value. Even so, I don't 
actually understand what value it brings over declaring the 
function const (maybe only callable by an immutable instance?).

What is wrong with the current template which returns an 
immutable delegate type? It still store you're immutable member 
function.

class Z {
     string a() immutable {
         return " 1";
     }
}

template F(t) {
     alias immutable(t) F;
}
alias typeof(&Z.init.a) Texpected;
alias typeof(&Z.init.a) T;

static assert(is(F!(T) : Texpected));
static assert(is(Texpected : F!(T) ));

void main() {}


More information about the Digitalmars-d-learn mailing list