This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Specialization in templates


Matthias Seeger wrote:

> Hello!
>
> When trying to compile code like
>
> template<class T> class A<T*> {};
>
> my EGCS compiler stops with "parse error before <'" (egcs-2.91.57,
> x86-linux). Does this mean that templete specialization (Stroustrup, 3rd
> ed., p.341) is not yet supported by EGCS?

Your example refer to "Partial Specialization" P.343.

Of course yes. Take a look at the following code:

#include <iostream>

template < class T >
struct  A
{
    // Default Constructor.
    A( void ) { cout << "Template A" << endl ; }
} ;

template < class T >
struct  A< T * >
{
    // Default Constructor.
    A( void ) { cout << "Partial Specialization A" << endl ; }
} ;

struct  A<int>
{
    // Default Constructor.
    A( void ) { cout << "Specialization A" << endl ; }
} ;

int  main ()
{
    A<double> ad ;
    A<int *>  pai ;
    A<int>    ai ;

    return  0 ;
}

> g++ -g main.cpp
> a.out

Template A
Partial Specialization A
Specialization A

CQFD.


>
>
> In that case: Are there any plans to support it in the near future? I
> consider it an highly valueable feature within the template framework.
> With specialization it is possible to realize nested types such as
>    vector<vector<...<vector<int>>...>>

Yes. I've already done a algorithm for a specialized type vector< vector<
int > >.
Add SmartPointer, and you've got an interminable line declaration ;-).

>
> of (potentially) arbitrary depth by implementing no more than 2 template
> classes:
>    template<class T> class A<vector<T> > and
>    template<class T> class A
>

If I don't mistake. You have by default a depth of 16 for templates.
Unless it's for template recursion or g++-2.7.2.3. I don't remember.
You must ask to one of the egcs coders...

Regards,

--
Jean-Michel Paris - Software Engineer
SITA Group http://www.sita.int
Internetworking Products & Services Program
Bât Héraklion - 1041 Route des Dolines
Sophia Antipolis
06560 VALBONNE - FRANCE
Tel: +33-04.92.96.64.95
mailto:Jean-Michel.Paris@pt.nce.sita.int
http://www.mygale.org/07/jmparis (Most Recent Update: 13 August 1998)




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]