Boost logo

Boost :

Subject: Re: [boost] [serialization] Proposal: make 'version' trait (andothers)enable_if-friendly
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-12-06 17:51:02

> Actually I'm still trying to wrap my head around why
> template<Foo<T>::MyType > doesn't work.

Imagine you had a main template:

template <typename T>
struct Bar

and suppose a partial specialization like this were allowed:

template <typename T>
struct Bar<Foo<T>::MyType>

Now suppose someone instantiates Bar<int>. The compiler has
to figure out whether to use the main template or the partial
specialization. How does the compiler do that?

In some special cases, it can be figured out (for example, if
Foo<T>::MyType is defined as T). However, in the general case,
Foo<T>::MyType can be the result of the some complicated
metafunction that depends on T. It is intractable for the
compiler to figure out what inputs to that metafunction (i.e.,
what values of T), yield a result of 'int'.

It is for the same reason that you can't do this in a template

template <typename T>
void bar(Foo<T>::MyType foo);

and expect that T will be deduced (it works if T is provided


Boost list run by bdawes at, gregod at, cpdaniel at, john at