C++ Limit template type to numbers
What you need std::is_arithmetic to constrain the template type to a arithmetic types (integral or floating point). You can use it like
template <typename T, typename std::enable_if<std::is_arithmetic<T>::value>::type* = nullptr>
void Deposit(T t) {...}
I am afraid you are getting wrong approach, you should create a class
that properly work with money (including necessary operations for your domain - adding, subtracting etc), test it, add methods to print it and/or convert to string, and make your function accept only that type:
class Money {
...
};
void Deposit( Money amount );
So by adding constructors you can control which types can be accepted:
class Money {
public:
explicit Money( double v );
explicit Money( int64_t cents );
Money( int64_t cents );
...
};
this way you can control what conversions can be done, and it would be done not only for this particular function but whole class
. Otherwise you will need to re-implement the same logic in many functions (I doubt your system only would need functionality to deposit).