This is not a deduced context. This is why the template argument cannot be deduced by the compiler.
Just imagine if you had a specialized TMap as follows:
template <> struct TMap<SomeType> { typedef std::map <double, double> Type; };
How would the compiler SomeType type, given that TMap<SomeType>::Type is std::map<double, double> ? It can't. It does not guarantee that the type you use in std::map is also a TMap type. The compiler cannot make this dangerous assumption. There can be no connection between type arguments.
In addition, you may have another TMap specialization defined as:
template <> struct TMap<OtherType> { typedef std::map <double, double> Type; };
This makes the situation worse. Now you have the following:
TMap<SomeType>::Type = std::map<double, double> .TMap<OtherType>::Type = std::map<double, double> .
Now ask yourself: given TMap<T>::Type is std::map<double, double> , how does the compiler know if there is T SomeType or OtherType ? He cannot even know how many such options he has, and he cannot know the choice itself ...
I just ask you for the sake of a thought experiment (assuming that he can know the full range of options).
Nawaz May 19 '11 at 15:15 2011-05-19 15:15
source share