// With one parameter, there's no problem
inline void Log(const char *fmt) { printf(fmt); }
// With 2 parameters, we check with a template function
template<class A
void Log(const char *fmt, A a)
{
CheckLogType(a);
printf(fmt, a);
}
// With 3 parameters, we check with a template function
template<class A, class B
void Log(const char *fmt, A a, B b)
{
CheckLogType(a);
CheckLogType(b);
printf(fmt, a, b);
}
// And we continue with 4, 5, 6, ... 26 parameters if you want
// We have just now to implement CheckLogType with acceptable types
inline void CheckLogType (int a) { }
inline void CheckLogType (unsigned int a) { }
inline void CheckLogType (char a) { }
inline void CheckLogType (unsigned char a) { }
inline void CheckLogType (long a) { }
inline void CheckLogType (unsigned long a) { }
inline void CheckLogType (float a) { }
inline void CheckLogType (double a) { }
inline void CheckLogType (const char *a) { }
inline void CheckLogType (const void *a) { } |