Sequence separation

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 17 12:39:33 PDT 2016


On 08/17/2016 09:21 PM, Lodovico Giaretta wrote:
> import std.traits: TemplateOf;
> static if (__traits(isSame, TemplateOf!(x.args[2]), MySequence))
> {
>     ...
> }
>
> std.traits.TemplateOf extracts the symbol representing the
> uninstantiated template.
>
> __traits(isSame, symbol1, symbol2) evaluates at compile time to true if
> and only if the two symbols represent the same thing (be it a type, an
> uninstantiated template, an instantiated one or whatever else).

Look at that! Much better.

TemplateOf is implemented with a template specialization, which can 
handle other things than types, unlike `is(...)`.

Using that directly, without going to std.traits, isMySequence could be 
done like this:

----
enum isMySequence(alias thing : MySequence!args, args ...) = true;
enum isMySequence(alias thing) = false;
----

That's just me toying around with the language, of course. The 
isSame+TemplateOf version is perfectly fine.


More information about the Digitalmars-d-learn mailing list