Determine if a type if derived from a template parameter
Basile B.
b2.temp at gmx.com
Thu Apr 11 08:57:10 UTC 2019
On Wednesday, 10 April 2019 at 19:28:38 UTC, Alex wrote:
> e.g.,
>
> class X(T,S)
> {
> T x;
> S y;
> }
>
> Somehow determine if x's type is derived from the template
> parameter.
>
> I doubt D has this capability but it would be nice for certain
> things. In my reflect library the types must be specified such
> as Reflect!(X!(int,float)) and ideally I would like to do
> Reflect!(X!(T,S)) to get generic reflection information. This
> helps reduce overhead as one could reflect once on the generic
> type, cache the results, then simply modify the results for
> specifics.
You can detect a match between a member and a template argument
but you cant know if the match is a coincidence or on purpose.
For example:
class X(T)
{
T x;
int y;
}
alias X1 = X!int;
here X1.y matches to T but it's a coincidence.
The problem that you'll be faced to is that the template
parameters are replaced by the symbol or the type.
More information about the Digitalmars-d
mailing list