Best way of checking for a templated function instantiation

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 10 06:35:12 PDT 2016


On Wednesday, 10 August 2016 at 12:36:14 UTC, Arafel wrote:
> Hi,
>
> I'm trying to check at compilation time if a given type 
> implements some operator (let's assume it's '+' in this case), 
> without caring about the type of the parameters it accepts. 
> Since operator overloading is expressed in D through templated 
> functions, what is the preferred way of checking if a template 
> is / can be instantiated with a given parameter list?
>
> [...]

static assert(is(typeof(S()+42)));
static assert(!is(typeof(S()-42)));


More information about the Digitalmars-d-learn mailing list