mercredi 22 avril 2015

Overloading function calls for compile-time constants

I'm interested to know whether one can distinguish between function calls using arguments provided by compile-time constants and those without?

For example:

int a = 2;
foo( a )  // #1: Compute at run-time
foo( 3 )  // #2: Compute at compile-time

Is there any way to provide overloads that distinguish between these two cases? Or more generally, how do I detect the use of a literal type?

I've looked into constexpr, but a function parameter cannot be constexpr. It would be neat to have the same calling syntax, but be able to generate different code based on the parameters being literal types or not.

Aucun commentaire:

Enregistrer un commentaire