Now that we know that Concepts is not part of C++0x, I am looking for methods to impose restrictions on types in template functions.
Here are two examples:
If we want to make sure that a given type is an integer, we can use:
template <class N> inline int f(const N n)
{
if ((N)0.1 != 0) // if type of N is floating-point
err()
....
}
if we want to make sure that a given type is an unsigned integer, we can use:
template <class N> inline int f(const N n)
{
if ((N)-1 < (N)1) // if type of N is floating-point / signed-integer
err()
....
}
I am looking for creative ways to check for additional restrictions, that will cause in failure in run-time, or better, in compile-time (without concepts and without RTTI).
Any suggestions?