chanwcom
chanwcom

Reputation: 4650

In a template method, Is there a way to check whether the current type is int-variant or float-variant?

I want to implement a template method for variable.

But depending on whether the input is a int-variant(char, short, int), I want to handle it somewhat differently from the case when the input is a float-variant (float, double, long double).

Is there a way to do this?

Upvotes: 0

Views: 61

Answers (1)

Revolver_Ocelot
Revolver_Ocelot

Reputation: 8785

To detect types:
http://en.cppreference.com/w/cpp/types/is_integral
http://en.cppreference.com/w/cpp/types/is_floating_point

Also look into SFINAE and tag dispatch to actually select implementation

Upvotes: 3

Related Questions