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

Timon Gehr timon.gehr at gmx.ch
Thu Jun 14 09:29:31 PDT 2012


On 06/14/2012 06:20 PM, Roman D. Boiko wrote:
> 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
>

You have found a compiler bug.


More information about the Digitalmars-d-learn mailing list