Now that we know that concepts are not part of C ++ 0x, I am looking for methods to impose type restrictions in template functions.
Here are two examples:
If we want to make sure that this 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 this 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 could lead to a crash at runtime or, better, at compile time (no concepts and no RTTI).
Any suggestions?
source
share