I was tinkering around with code in C++ last night trying to make a template algorithm that would be evaluated at compile time and also print information.
Unfortunately, because std::cout and std::cin are references to objects and they aren't considered built in types (directly at least), I suppose the compiler considers them variable and not a "constant expression," so statements like the following--
template<int N>
class PrintInfo{
enum {RESULT = ((std::cout << N << (N == 1) ? std::endl : std::flush ) , N) + PrintInfo<N-1>::RESULT};
};
template<>
class PrintInfo<0>{
enum {RESULT = 0};
};
--are unallowed.
The same problem occurs if I try to specify a reference (or pointer) argument to the template, as well as pointer to function... etc. Basically anything that cannot be resolved at compile time due to its chance to vary will be unworkable.
What I'd like is a way to print the information at compile-time. I know for a fact that if the compiler is capable of doing parsing and optimizations during compile-time, it can at least flag what it is doing (possibly) in the error-window.
I'm using Microsoft Visual 2005/2008 compiler, on Windows XP.
-Alex