test if the alias of a template is a literal
Basile B. via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 27 20:40:28 PDT 2016
On Friday, 28 October 2016 at 03:33:33 UTC, Basile B. wrote:
> On Thursday, 27 October 2016 at 14:04:23 UTC, Gianni Pisetta
> wrote:
>> So i searched for a metod to check if an alias is a literal
>> value, but found nothing. Anyone have any clue on how can be
>> done?
>>
>> Thanks,
>> Gianni Pisetta
>
> Hello, I think the correct isStringLiteral would be:
>
> import
> std.meta;
>
> template isStringLiteral(alias V)
> {
> enum isCompileTime = is(typeof((){enum a = V;}));
> enum isString = is(typeof(V) == string);
> enum isStringLiteral = isCompileTime && isString;
> }
>
> [...]
In addition a fallback for the types must be added:
template isStringLiteral(V){enum isStringLiteral = false;}
More information about the Digitalmars-d-learn
mailing list