I have the following problem:
I want to define between two types without actually evaluating the "resulting" types - since the type may not exist at all - is invalid. (Please do not use C ++ 11)
Example:
#include <iostream> #include <iterator> template <bool B, typename T, typename F> struct TemplateIf { }; template <typename T, typename F> struct TemplateIf<true, T, F> { typedef T Result; }; template <typename T, typename F> struct TemplateIf<false, T, F> { typedef F Result; }; int main(int argc, char** argv) { // On GCC this is error as std::iterator_traits<int>::value_type doesn't exist typename TemplateIf<true, int, std::iterator_traits<int>::value_type >::Result a; a = 5; std::cout << a << std::endl; return 0; }
Is there any way to determine this? (Assuming the selected type is always valid, but not the selected type may be invalid).
source share