Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2005-02-07 13:57:47


On Sunday 06 February 2005 16:24, Ian McCulloch wrote:
>
> template <typename T>
> struct bar
> {
> typedef typename T::this_type_does_not_exist type;
> };
>
> No error here in the declaration, but at the point of instantiating bar<X>,
> X::this_type_does_not_exist must have been previously declared. Note that
> this declaration would also cause the instantiation of X itself.

> The rule of thumb is, whenever a template is instantiated all of the
> declarations must be legal - so all the typedefs must be previously
> declared types. That does not cause member functions to be instantiated
> though. Simply naming a templated type does not cause it to be
> instantiated either. eg, it would be fine to declare a template function
> that returns bar<void>. It would be an error to instantiate it though,
> because that would require instantiating the bar<void> copy-ctor and
> bar<void> is erroneous. It would be OK if it was a pointer or reference to
> bar<void> though, I think, similarly to the case of pointers to incomplete
> types.

Ian,
Thanks for the more detailed explanation. I must have been dreaming that the
SFINAE (substitution failure is not an error) also applied to (dependant)
type declerations in classes. I guess I was misinterpreting the rules on
instantiation here. Your example with bar<void> is interesting. I did start
to wonder when GCC-3.4 complained that it was wrong!

It is a good job Karl has already committed his temporay_traits mechanism. The
mechanism in 1.32.0 turns out to be rather broken! Still it is better then
the previous situation where arbitrary temporary types were used in all
cases.

Cheers,
        Michael