Using "cast(enum)" for explicit request of ctfe

monarch_dodra monarchdodra at gmail.com
Wed Dec 4 23:58:42 PST 2013


On Thursday, 5 December 2013 at 07:36:30 UTC, luka8088 wrote:
> On 4.12.2013. 16:28, monarch_dodra wrote:
>> 
>> I mean that:
>> 
>> auto a = eval!(1 + 2);
>> a += 1; // <= cannot modify immutable expression 3
>> 
>> Should work.
>
> I don't think so. With type inference a is immutable.
>
> int a = eval!(1 + 2);
>
> Works.

Right, but that's my point. If you use an enum, as opposed to a 
global immutable, it *does* work.

Also, your rebuke works for the trivial int type, but not for a 
more complicated type with indirection, such as a dynamic array, 
and even less so a struct with a complex structure.

--------

Having a template that stores a single global-static-immutable 
value also has its uses (which I have *also* used in phobos, more 
than once. But:
a) It's for a different use case.
b) The use cases where specific enough that not having 
"on-the-fly" template to do it.


More information about the Digitalmars-d mailing list