Consider the following code:
#include <iostream>
template<class T>
struct outer {
struct inner {};
};
template<class T>
std::ostream& operator<<(std::ostream & stream,
typename outer<T>::inner const& value) {
std::cout << "An outer::inner!";
return stream;
}
int main() {
outer<float>::inner foo;
std::cout << foo << std::endl; // does not compile
}
This does not compile, because typename outer<T>::inner
is a nondeduced context (as explained here), meaning the template-argument-type cannot be deduced by the compiler (read this answer for the why). As I see it, I have two options to make it work:
- Move
inner
outside ofouter
and make it a class-template. I prefer this one, because the impact on the using code is smaller. - Add a
to_string
-method to inner.
Are there any other solutions for this (that do not result in ugly syntax in the using code)?