Hi guys,
Thanks for your responce.
Come to think about it, I do realize that overloading on a nested
typedef in this context (at least in my case) doesn't make a lot of
sense. The nested typedef may after all resolve to different types,
like:
template<class T>
struct A1
{};
template<class T>
struct A2
{};
template<class T>
struct B
{
// something like:
typedef select<some_condition_based_on_T, A1<T>, A2<T> >::type type;
};
For both A1 and A2 I need to define a separate overloaded function.
So I actually have to overload on A1<T> and A2<T>, rather than on
B<T>::type.
Regards,
Arkadiy
tom_usenet <tom_usenet@hotmail.com> wrote in message news:<9ji8nvoe0g7mi41f53juinh9iena9rhq0v@4ax.com>. ..[color=blue]
> On 26 Sep 2003 14:09:31 GMT, Gianni Mariani <gi2nospam@mariani.ws>
> wrote:
>[color=green]
> >tom_usenet wrote:[color=darkred]
> >> On 25 Sep 2003 19:27:16 -0700,
vertleyb@hotmail.com (Arkadiy Vertleyb)
> >> wrote:
> >>
> >>
> >>>Hi all,
> >>>
> >>>I am having a problem trying to overload a function template, based on
> >>>a typedef, such as:
> >>>
> >>>template<class T>
> >>>struct A
> >>>{};
> >>>
> >>>template<class T>
> >>>struct B
> >>>{
> >>> typedef A<T> type;
> >>>};
> >>>
> >>>template<class T>
> >>>void foo(const typename B<T>::type&)
> >>
> >>
> >> The above contains a non-deducable context (in this case, a nested
> >> type).[/color]
> >
> >
> >What's non-deductible about it ?[/color]
>
> It attempts to deduce a template parameter from the type of a typedef
> of the template. 14.8.2.4/4 is the relevent bit of the standard.
>[color=green]
> >const typename B<T>::type& <<>> B<int>::type
> >
> >infers T is int. right ?[/color]
>
> No, and the deduction can't even reliably be made. e.g.
>
> template<>
> struct B<float>
> {
> typedef A<int> type; //whoops, now which B?
> };
>
> Of course, this could just cause an ambiguity error, as it does in
> VC6. However, the mapping from inner type to template parameter is not
> always many-to-one, so the committee decided to forbid it.
>[color=green]
> >
> >How does the standard define non-deductible ?[/color]
>
> Read up on nondeduced contexts.
>
> Tom[/color]