Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-04-20 18:36:23


Jason Hise wrote:
> The following specialization fails to compile on .NET 2002. Is there
> a good reason as to why, and if not, is there a suggested work around?
>
> template < typename T >
> class A
> {
> };
>
> template < typename T >
> class B
> {
> };
>
> template < typename T >
> class A < B < T > > // this is the specialization
> {
> };

This is partial specialization, which VC didn't support until version 7.1.

If you're working from scratch, there are some workarounds using nested
templates; see, e.g., http://www.boost.org/boost/pending/ct_if.hpp.

Using mpl, you might do:

   template<typename T>
   struct is_B;

   template<typename T>
   struct A_primary { /* ... */ };

   template<typename T>
   struct A_specialized { /* ... */ };

  template<typename T>
  struct A
     : mpl::if_<
           is_B<T>,
           A_primary <T>,
           A_specialized<T>
>::type
  {
       /* Ctors, etc. */
   }

Here it is often sufficient to implement is_B<> using the "sizeof trick". If you
are the author of B, and you need is_B<T> to be defined exactly, you can give
B<T> a typedef identifying T and use is_same<> together with has_xxx from mpl.
I'd say more but I have to run.

Jonathan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk