0

Is it possible to put compile-time conditional code in template functions?

Kinda like,

template <class T>
void print(T &foo){
  cout << foo;
#if T == float
  cout << " is a float." << endl;
#endif
}

Something like that, I hope I made myself clear.

Thanks in Advance,

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Clockowl
0

Nope, the preprocessor ONLY works before compile time, remember that, so you cant have a mix of the two :)

edit: but maby you should look at the typeid operator, it might be what you need for that example.

0

Err, template specialization seems to be the way to go for me, but thanks for the effort. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.