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

Jakob Ovrum jakobovrum at gmail.com
Wed Dec 4 03:51:10 PST 2013


On Wednesday, 4 December 2013 at 11:41:53 UTC, monarch_dodra 
wrote:
> On Wednesday, 4 December 2013 at 11:32:40 UTC, Jakob Ovrum 
> wrote:
>> On Wednesday, 4 December 2013 at 11:12:54 UTC, monarch_dodra 
>> wrote:
>>> Or, if somebody has an idea of how to do this via a library 
>>> solution?
>>
>> alias eval(alias exp) = exp;
>
> Nice :D
>
> Very very nice. Though that should be "enum" I think.
>
> I think having this somewhere in Phobos would be a great 
> addition.
>
> Not sure "eval" would be correct though, as "eval" tends to 
> imply parsing.
>
> I'll just file a simple ER then. Where would we put such an 
> addition?

Right, maybe it should be (substitute the name `eval`):

---
template eval(alias exp) if(isExpressionTuple!exp)
{
     static immutable eval = exp;
}
---

Which might make it avoid the pitfalls of using enum. Not sure if 
the `static` actually does something in this context, IIRC it 
does not.

No idea where to put it. I've experimented with such a template 
before but I haven't used it in any real code. object.d and 
std.typecons come to mind, but I don't particularly like the 
prospect of putting it in either.


More information about the Digitalmars-d mailing list