One template specialization for multiple classes

Posted by peper0 on Stack Overflow See other posts from Stack Overflow or by peper0
Published on 2010-03-12T02:04:12Z Indexed on 2010/03/12 2:07 UTC
Read the original article Hit count: 467

Filed under:
|
|

Let's assume we have a template function "foo":

template<class T>
void foo(T arg)
{ ... }

I can make specialization for some particular type, e.g.

template<>
void foo(int arg)
{ ... }

If I wanted to use the same specialization for all builtin numeric types (int, float, double etc.) I would write those lines many times. I know that body can be thrown out to another function and just call of this is to be made in every specialization's body, however it would be nicer if i could avoid writting this "void foo(..." for every type. Is there any possibility to tell the compiler that I want to use this specialization for all this types?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates