How do I check if this field is of this template struct?
Jack
jckj33 at gmail.com
Fri Mar 19 16:35:52 UTC 2021
On Friday, 19 March 2021 at 07:56:26 UTC, Panke wrote:
> On Friday, 19 March 2021 at 07:14:46 UTC, Jack wrote:
>> give below template struct, how can I list the members x, y
>> and z? I've tried something with OriginalType and TemplateOf
>> but no luck... it seems if I do foo!"str1" the "str1" became
>> "part of type"? give .stringof from typeof(__traits(getMember,
>> foo, field)) I thought the type would be foo!string or
>> something.
>
> Template parameter cannot only be types but also values,
> including strings. If you instantiate a template with different
> values you get different types.
that design is a bit different but may be worth, gonna get used
to it
> --
> struct foo(T) { }
> struct bar(string s) {}
>
> alias a = foo!string; // type of a is foo!string
> alias b = bar!"str1"; // type of b is bar!"str1"
> alias c = bar!"str2"; // typo of c is bar!"str2"
> static assert (!is(typeof(c) == typeof(b)));
> --
More information about the Digitalmars-d-learn
mailing list