Best way of checking for a templated function instantiation

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 10 07:09:21 PDT 2016


On Wednesday, 10 August 2016 at 13:57:54 UTC, Arafel 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!\"+\"")

Unfortunately you're stuck using __traits(compiles) as 
`opBinary!"+"` is not a symbol.

static assert(__traits(compiles, { alias _ = S.opBinary!"+"; }));


More information about the Digitalmars-d-learn mailing list