How to specialize templates for l-value and non-l-value arguments?

Roman D. Boiko rb at d-coding.com
Thu Jun 14 09:20:57 PDT 2012


On Thursday, 14 June 2012 at 16:08:54 UTC, Roman D. Boiko wrote:
> On Thursday, 14 June 2012 at 16:05:52 UTC, Timon Gehr wrote:
>> You can overload based on 'ref'.
>>
>> auto just(ref immutable(T) data) { return Maybe!T(&data); }
>> auto just(immutable(T) data) { return Maybe!T([data].ptr); }
> Great! Thanks
Hmm... seems to fail for immutable:

immutable a = 2.0f;
#line 121
auto y0 = Maybe!float.just(a);
assert(!y0.empty);
assert(y0.front == a);

Compiler output:
fds/persistent.d(121): Error: 2 is not an lvalue
dmd: glue.c:1114: virtual unsigned int Type::totym(): Assertion 
`0' failed.
Aborted (core dumped)
make: *** [build/client] Error 134



More information about the Digitalmars-d-learn mailing list