Sparse Aggregate Assignment/Initialization (RAII)
Justin Whear via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 7 14:50:22 PDT 2014
On Mon, 07 Jul 2014 21:49:22 +0000, Justin Whear wrote:
> On Mon, 07 Jul 2014 21:34:05 +0000, Nordlöw wrote:
>
>> However using this function through UFCS
>>
>> auto cx = new C().set!"x"(11);
>>
>> fails as
>>
>> algorithm_ex.d(1257,17): Error: template algorithm_ex.set cannot deduce
>> function from argument types !("x")(C, int), candidates are:
>> algorithm_ex.d(1242,7): algorithm_ex.set(string member, T,
>> U)(ref T a, in U value) if (isAggregateType!T && hasMember!(T,
>> member))
>>
>> Instead I have to use
>>
>> auto c = new C(); set!"x"(c, 11);
>>
>> which is not as elegant.
>>
>> Why doesn't UCFS work here and is there a solution using DMD git
>> master?
>
> You need to use `auto ref` to have this work with both classes and
> structs. A working version of your code here: auto dx =
> D().set!"x"(11);
> assert(dx.x == 11);
Copy and paste gone astray; should be this link:
http://dpaste.dzfl.pl/3c33ad70040f
More information about the Digitalmars-d-learn
mailing list