How do I check if this field is of this template struct?
Panke
tobias at pankrath.net
Fri Mar 19 07:56:26 UTC 2021
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.
--
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