473,465 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Specialization of a template within template

Is it possible to specialize a templated class defined within another
templeted class, like below:

template<typename U>
struct A
{ template<typename T>
struct B;
};

// Attempt to specialize internal class B for type int
template<typename U>
struct A<U>::B<int> {};

typedef A<long>::B<int> MyType; // this causes a failure

Online Comeau C++ fails without a message.
What is the right syntax, if any, for such specializations ?

Thanks,

Nikolai Borissov
Jul 19 '05 #1
2 2905
"Nikolai Borissov" <n.********@sympatico.ca> wrote in message
news:iV********************@news20.bellglobal.com. ..
Is it possible to specialize a templated class defined within
another templeted class, like below:
[...]


I've been told that it isn't legal C++, but looking at 14.7 makes
me think otherwise. I don't have my copy of C++T handy, so
I can't look there. You might want to ask in c.l.c++.m, as some
more knowledgeable readers tend to visit there.

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
Jul 19 '05 #2
Nikolai Borissov wrote in news:iVGmb.10683$7t3.492363
@news20.bellglobal.com:
Is it possible to specialize a templated class defined within another
templeted class, like below:

template<typename U>
struct A
{ template<typename T>
struct B;
};

// Attempt to specialize internal class B for type int
I changed this to:
template <typename U> template <>
struct A<U>::B<int> {};

gcc 3.2:
test.cpp:14: enclosing class templates are not explicitly specialized
test.cpp:15: template parameters not used in partial specialization:
test.cpp:15: `U'

msvc 7.1: test.cpp:14: error C3212: 'A<U>::B<int>' : an explicit
specialization of a template member must be a member of an explicit
specialization
test.cpp:15: see declaration of 'A<U>::B<int>'

online EDG: a template declaration containing a template parameter list
may not be followed by an explicit specialization declaration
template <typename U> template <>
template<typename U>
struct A<U>::B<int> {};

typedef A<long>::B<int> MyType; // this causes a failure

Online Comeau C++ fails without a message.
What is the right syntax, if any, for such specializations ?


I don't think there is any.

I'd suggest switching the problem around:

template <typename T>
struct B_inner
{
template<typename U>
struct A_outer {};
};
/* Specialize this as meny times as we want
*/
template <>
struct B_inner< int >
{
template <typename U>
struct A_outer
{
};
};

template<typename U>
struct A
{
template <typename T>
struct B : public B_inner< T >::template A_outer< U >
{
};
};

typedef A<long>::B<int> MyType; // this causes a failure

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
4
by: sks_cpp | last post by:
I need help with the following. I feel like I am pretty good at templates but I can't figure out the following: I have two templates: template <int> struct Mgmt { };
8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
2
by: Jonathan Turkanis | last post by:
Hi All, The simple test program at the end of this message defines a class template foo with a member function bar implemented by delegating to a static member function of a specialization of...
5
by: __PPS__ | last post by:
Hello, I want to write specialized method for a class: template<class A, class B> class xxx{ A a; B b; operator bool()const{ a==b; } };
2
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
6
by: abir | last post by:
i have a template as shown template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.