C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template template partial specialisation advice needed

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
matt
Guest





PostPosted: Sun Jan 23, 2005 3:02 am    Post subject: template template partial specialisation advice needed Reply with quote



Hi All,

Quote:
From spending an hour reading previous posts to this group, I have
found these types of questions continually arise. Here is another that

I have been wrestling with that appears not to have been specifically
discussed. I have been having problems with the following simpler
scenario (ie in a short form):

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

template <template
class E {
typedef typename D::some_type some_type;
....
some_type doIt();
....
};

--- compiles fine up to here ---

template <typename D>
E<B, D>::some_type
E<B, D>::doIt() { <== errors appear for this line
....
}

gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3) complains:
expected init declarator before 'E'
expected ; before 'E'


In other words, I would like to specialise E::doIt() for the case where
B is the supplied model of C. Somehow I thought this would be as easy
as a template partial specialization... :-)


Thanks, Matt


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Efrat Regev
Guest





PostPosted: Sun Jan 23, 2005 10:16 am    Post subject: Re: template template partial specialisation advice needed Reply with quote



"matt" <dmatt001 (AT) yahoo (DOT) com> wrote

Quote:
Hi All,

In other words, I would like to specialise E::doIt() for the case where
B is the supplied model of C. Somehow I thought this would be as easy
as a template partial specialization... Smile

From looking at your code, it seems indeed that your problem does not
lie with template templates. Here is a simplification of
your code (I've eliminated template templates):

// For simplicity, B is now not a template
class B{};

// For simplicity, C is not, itself, a template
template<typename C, typename D>
class E
{
typedef typename D::some_type some_type;

some_type doIt();
};


/*****************/Problems!
**************************
// Following is problematic (won't compile)
template<typename D>
E<B, D>::some_type // especially, this line
E<B, D>::doIt()
{
}
/*****************/Problems!
**************************

Now your modified code contains no template templates, but still won't
compile. As far as I undersand, the code I surrounded by asterikses has two
problems:
1. The compiler sees a method of a specialization of E which is never
declared.
2. It has no idea what is E<B, D>::some_type

Here's how to fix this (your original version):

template<typename A>
class B{};

template<template
class E
{
typedef typename D::some_type some_type;

some_type doIt();
};


// Specialize the entire class
template<typename D>
class E<B, D>
{
typedef typename D::some_type some_type;

some_type doIt();
};


template<typename D>
// notice change in next line
typename E<B, D>::some_type
E<B, D>::doIt()
{
}


____________________________________________________

(Note that while the code above compiles, it is problematic. E.g., the
line "typedef typename D::some_type some_type;" appears twice. This can be
solved by various means, for example, by inheriting both the primary E and
specialized E from the same base class).

Possibly, you might want to read "C++ Templates: the Complete Guide" by
Vandevoorde and Jossutis.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Carl Barron
Guest





PostPosted: Sun Jan 23, 2005 10:18 am    Post subject: Re: template template partial specialisation advice needed Reply with quote



In article <1106438996.985790.273250 (AT) c13g2000cwb (DOT) googlegroups.com>,
matt <dmatt001 (AT) yahoo (DOT) com> wrote:

Quote:
Hi All,

From spending an hour reading previous posts to this group, I have
found these types of questions continually arise. Here is another that
I have been wrestling with that appears not to have been specifically
discussed. I have been having problems with the following simpler
scenario (ie in a short form):

template <typename A
class B {
...
};

template