Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-04-18 12:37:40

Michael Marcin wrote:
> IIUC what that forward declared partial specialization is doing is akin to
> saying:
> - I know the default implementation of tag_of can't be correct for
> boost::array<T,N>
> - There should be an implementation of tag_of that will make it work for
> boost::array<T,N>
> - I don't know what that implementation is, you or someone else better
> provide it

Yes. It's done to prevent (different kinds of) ODR violations.

Example 1:

     template<typename T> struct X { };
     template<typename T> struct Y { };

     // [...] <--- 'X< Y<void> >' gets instantiated

     template<typename T> struct X< Y<void> >
        // !!! ERROR, already defined

Example 2:

     // first translation unit includes
     template<typename T> struct is_xyz : mpl::false_ { };
     template<> struct is_xyz<void> : mpl::true_ { };

     // now is_xyz<xyz>::value == true


     // second translation unit misses to include the specialization
     template<typename T> struct is_xyz : mpl::false_ { };

     // now is_xyz<xyz>::value == false

Note there are compilers that happily compile and link example 2.

> Is it then true that when proper definition of the partial specialization is
> provided this partial specialization of the declaration has no effect
> whatsoever?

Yes, once the type is completed it's complete ;-). It just prevents the
type to be completed prematurely by instantiating the primary template.

> If that is true and this is a compiler bug then perpahs we can use a
> simply omit these these forward declarations on compilers that choke on them
> (like CW 9.4 apparerently does).

Are you sure it only applies to /partial/ specializations? How about the
full ones?

My suggestions for the names would be:





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