Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function overloading for "integral" types

Suppose there are types of "temperature"(T) and "distance"(D). Both, indeed, could be declared as usual typedefs:

typedef int T; // might be C++11 'using' 
typedef int D;

But if I want an overloaded functions:

void f(T) {}  
void f(D) {}

it will not work, because both types are identical.

Which most modern C++-way to realize such an overload?

It is clear that for those types must be distinguishable for compiler.

like image 826
αλεχολυτ Avatar asked Dec 11 '22 04:12

αλεχολυτ


1 Answers

BOOST_STRONG_TYPEDEF is made exactly for this purpose.

like image 86
user541686 Avatar answered Dec 25 '22 20:12

user541686