Best way of checking for a templated function instantiation

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 10 07:04:51 PDT 2016


On Wednesday, August 10, 2016 13:57:54 Arafel via Digitalmars-d-learn wrote:
> On Wednesday, 10 August 2016 at 13:40:30 UTC, Meta wrote:
> > On Wednesday, 10 August 2016 at 13:37:47 UTC, Meta wrote:
> >> static assert(__traits(compiles, auto _ =
> >> S.init.opBinary!"+"(int.init));
> >
> > Made a typo, this should be:
> >
> > static assert(__traits(compiles, { auto _ =
> > S.init.opBinary!"+"(int.init); }));
>
> Hi!
>
> Thanks, that would do! Just out of curiosity, would there be any
> way to check just that the function is defined, like what
> "hasMember" would do, without caring about argument number,
> types, etc.? Ideally something like:
>
> __traits(hasMember, S, "opBinary!\"+\"")

__traits(allMembers, S) would give "opBinary", so I don't think so. You can
check that the type defined an overloaded binary operator but not which one.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list