C++ STL type_traits question.
- by Kim Sun-wu
I was watching the latest C9 lecture and noticed something interesting..
In his introduction to type_traits, Stephan uses the following (as he says, contrived) example:
template <typename T> void foo(T t, true_type)
{
std::cout << t << " is integral";
}
template <typename T> void foo(T t, false_type)
{
std::cout << t << " is not integral";
}
template <typename T> void bar(T t)
{
foo(t, typename is_integral<T>::type());
}
This seems to be far more complicated than:
template <typename T> void foo(T t)
{
if(std::is_integral<T>::value)
std::cout << "integral";
else
std::cout << "not integral";
}
Is there something wrong with the latter way of doing it? Is his way better? Why?
Thanks.