0

I hava overloaded stream operator << for a new template type X<T> and that works. But if I wrap that type with the identity function identity<X<T>>::type the code breaks.

I tried gcc 4.6.2 / gcc 4.8.1 / clang 3.3

Any hint?

#include <iostream>

template <typename T>
struct ebenso // because I could not find std::identity, any hint?
{
        typedef T type;
};

template <typename T>
struct X
{
        T value;
};

template<typename T>
inline std::ostream  & 
operator << (std::ostream& stream, typename ebenso< X<T> >::type const & x)
{
        return stream << x.value << std::endl;
}

int main ()
{
        X<int> x;
        x.value = 7;
        std::cout << x << std::endl; // The overload is not found
}
Patrick Fromberg
  • 1,313
  • 11
  • 37
  • 1
    You want a template type that is the same as its template parameter? Why? – David Brown Oct 05 '13 at 06:03
  • 3
    There is no std::identity. The whole point of identity is to prevent the compiler from guessing what T is, so you have to call operator<< (std::cout,x). That's because it creates a non-deducible context. Alias templates don't have that effect. – Marc Glisse Oct 05 '13 at 06:05
  • @Marc, you are completely correct, it is not the overload resolution that fails but the type deduction. – Patrick Fromberg Oct 05 '13 at 06:33

0 Answers0