Template specialization 
Author Message
 Template specialization

Hi

I have two class templates:

template <class T>
class A
{

Quote:
};

template <class T>
class B
{

Quote:
};

How can I provide a specialized version of B for all instances of A<>?

I. e. something like:

template <class T>
template <>        // C2988
class B < A<T> >
{
//...

Quote:
};

TIA
Holger


Wed, 26 May 2004 18:42:49 GMT  
 Template specialization
Partial specialization is what you want ... the correct syntax would be:

template<typename T>
class B<A<T> > {

Quote:
};

Unfortunately partial specialization is not supported in Visual C++ 7.0 -
though it will be supported in a future release of the product.

--
Jonathan Caves
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

http://www.microsoft.com/info/cpyright.htm.

Quote:
> Hi

> I have two class templates:

> template <class T>
> class A
> {
> };

> template <class T>
> class B
> {
> };

> How can I provide a specialized version of B for all instances of A<>?

> I. e. something like:

> template <class T>
> template <>        // C2988
> class B < A<T> >
> {
> //...
> };

> TIA
> Holger



Sat, 29 May 2004 00:38:09 GMT  
 Template specialization
Thanks Jonathan,

Is there any workaround available?

Cheers
Holger



Quote:
> Partial specialization is what you want ... the correct syntax would be:

> template<typename T>
> class B<A<T> > {
> };

> Unfortunately partial specialization is not supported in Visual C++ 7.0 -
> though it will be supported in a future release of the product.

> --
> Jonathan Caves
> Microsoft Corporation

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
> reserved.

> http://www.microsoft.com/info/cpyright.htm.


> > Hi

> > I have two class templates:

> > template <class T>
> > class A
> > {
> > };

> > template <class T>
> > class B
> > {
> > };

> > How can I provide a specialized version of B for all instances of A<>?

> > I. e. something like:

> > template <class T>
> > template <>        // C2988
> > class B < A<T> >
> > {
> > //...
> > };

> > TIA
> > Holger



Sat, 29 May 2004 03:19:19 GMT  
 Template specialization
Unfortunately there is not an easy workaround - you sometimes can use nested
class to acheive the same effect but not always.

--
Jonathan Caves
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

http://www.microsoft.com/info/cpyright.htm.

Quote:
> Thanks Jonathan,

> Is there any workaround available?

> Cheers
> Holger



> > Partial specialization is what you want ... the correct syntax would be:

> > template<typename T>
> > class B<A<T> > {
> > };

> > Unfortunately partial specialization is not supported in Visual C++
7.0 -
> > though it will be supported in a future release of the product.

> > --
> > Jonathan Caves
> > Microsoft Corporation

> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > You assume all risk for your use. ? 2001 Microsoft Corporation. All
rights
> > reserved.

> > http://www.microsoft.com/info/cpyright.htm.


> > > Hi

> > > I have two class templates:

> > > template <class T>
> > > class A
> > > {
> > > };

> > > template <class T>
> > > class B
> > > {
> > > };

> > > How can I provide a specialized version of B for all instances of A<>?

> > > I. e. something like:

> > > template <class T>
> > > template <>        // C2988
> > > class B < A<T> >
> > > {
> > > //...
> > > };

> > > TIA
> > > Holger



Sat, 29 May 2004 05:17:34 GMT  
 Template specialization

Quote:
> Thanks Jonathan,

> Is there any workaround available?

> Cheers
> Holger

I'd suggest visiting the Boost-Users mailing list (you can find subscription
information at www.boost.org) and posting this question there.  Some of the
Boosters have developed quite sophisticated techniques for getting by
without PTS.  There was even talk of someone putting together a document
(could be a whole book) on the techniques.

-cd



Sat, 29 May 2004 08:47:47 GMT  
 Template specialization
Thanks again Jonathan,

It seems there is a quite simple workaround using the __if_exists :

template <typename T>
class B
{
    __if_exists ( T::A )    // A ctor ?
    {
        // specialization for A
    }
    __if_not_exists ( T::A )
    {
        // standard
    }

Quote:
};

Not very elegant but it should produce exactly the same result as the PTS
version. Could you confirm that?
BTW is it possible to check for a specific overload with __if_exists.

Cheers
Holger



Quote:
> Unfortunately there is not an easy workaround - you sometimes can use
nested
> class to acheive the same effect but not always.

> --
> Jonathan Caves
> Microsoft Corporation

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
> reserved.

> http://www.microsoft.com/info/cpyright.htm.


> > Thanks Jonathan,

> > Is there any workaround available?

> > Cheers
> > Holger


message

> > > Partial specialization is what you want ... the correct syntax would
be:

> > > template<typename T>
> > > class B<A<T> > {
> > > };

> > > Unfortunately partial specialization is not supported in Visual C++
> 7.0 -
> > > though it will be supported in a future release of the product.

> > > --
> > > Jonathan Caves
> > > Microsoft Corporation

> > > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
> > > You assume all risk for your use. ? 2001 Microsoft Corporation. All
> rights
> > > reserved.

> > > http://www.microsoft.com/info/cpyright.htm.


> > > > Hi

> > > > I have two class templates:

> > > > template <class T>
> > > > class A
> > > > {
> > > > };

> > > > template <class T>
> > > > class B
> > > > {
> > > > };

> > > > How can I provide a specialized version of B for all instances of
A<>?

> > > > I. e. something like:

> > > > template <class T>
> > > > template <>        // C2988
> > > > class B < A<T> >
> > > > {
> > > > //...
> > > > };

> > > > TIA
> > > > Holger



Sat, 29 May 2004 19:26:12 GMT  
 Template specialization
No __if_exists cannot be used on a specific overload. BTW: once we have
partial specialization __if_exists is likely to be deprecated.

--
Jonathan Caves
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

http://www.microsoft.com/info/cpyright.htm.

Quote:
> Thanks again Jonathan,

> It seems there is a quite simple workaround using the __if_exists :

> template <typename T>
> class B
> {
>     __if_exists ( T::A )    // A ctor ?
>     {
>         // specialization for A
>     }
>     __if_not_exists ( T::A )
>     {
>         // standard
>     }
> };

> Not very elegant but it should produce exactly the same result as the PTS
> version. Could you confirm that?
> BTW is it possible to check for a specific overload with __if_exists.

> Cheers
> Holger



> > Unfortunately there is not an easy workaround - you sometimes can use
> nested
> > class to acheive the same effect but not always.

> > --
> > Jonathan Caves
> > Microsoft Corporation

> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > You assume all risk for your use. ? 2001 Microsoft Corporation. All
rights
> > reserved.

> > http://www.microsoft.com/info/cpyright.htm.


> > > Thanks Jonathan,

> > > Is there any workaround available?

> > > Cheers
> > > Holger


> message

> > > > Partial specialization is what you want ... the correct syntax would
> be:

> > > > template<typename T>
> > > > class B<A<T> > {
> > > > };

> > > > Unfortunately partial specialization is not supported in Visual C++
> > 7.0 -
> > > > though it will be supported in a future release of the product.

> > > > --
> > > > Jonathan Caves
> > > > Microsoft Corporation

> > > > This posting is provided "AS IS" with no warranties, and confers no
> > > rights.
> > > > You assume all risk for your use. ? 2001 Microsoft Corporation. All
> > rights
> > > > reserved.

> > > > http://www.microsoft.com/info/cpyright.htm.


> > > > > Hi

> > > > > I have two class templates:

> > > > > template <class T>
> > > > > class A
> > > > > {
> > > > > };

> > > > > template <class T>
> > > > > class B
> > > > > {
> > > > > };

> > > > > How can I provide a specialized version of B for all instances of
> A<>?

> > > > > I. e. something like:

> > > > > template <class T>
> > > > > template <>        // C2988
> > > > > class B < A<T> >
> > > > > {
> > > > > //...
> > > > > };

> > > > > TIA
> > > > > Holger



Sun, 30 May 2004 00:45:33 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Template specialization problem (not partial-specialization)

2. Template specialization trouble

3. Partial template specialization problem?

4. Static constant definition and explicit template specialization

5. Template specialization

6. Release plan for partial template specialization?

7. Partial Template Specialization?

8. Partial template specialization??

9. partial template specialization

10. template specialization and redeclaration and redefinition of members

11. template specialization problem

12. Template Specialization Question

 

 
Powered by phpBB® Forum Software