473,408 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Recursive partial specialization

Hi. I have a template with 3 params:

template <typename BASE, typename SUPER=void, typename SUPER2=void>
Coolness
{
};

typedef Coolness<long> LongCoolness;
typedef Coolness<long, bool> LongAndBoolCoolness;

OK, this is the trick here. When the template is typedefed in this
form:

typedef Coolness<BASE, Coolness<T1, T2>, void> Thing;

IE with a Coolness as a second parameter, I then want T1 and T2 to be
the parameters instead:

typedef Coolness<BASE, T1, T2> Thing;

Can I accomplish with partial specialization?

Thanks very much
Dan

Jul 23 '05 #1
1 1489
On 27 Apr 2005 16:45:58 -0700, da*************@gmail.com wrote:
Hi. I have a template with 3 params:

template <typename BASE, typename SUPER=void, typename SUPER2=void>
Don't forget a 'struct' or 'class' keyword.
Coolness
{
};

typedef Coolness<long> LongCoolness;
typedef Coolness<long, bool> LongAndBoolCoolness;

OK, this is the trick here. When the template is typedefed in this
form:

typedef Coolness<BASE, Coolness<T1, T2>, void> Thing;

IE with a Coolness as a second parameter, I then want T1 and T2 to be
the parameters instead:

typedef Coolness<BASE, T1, T2> Thing;

Can I accomplish with partial specialization?

You can't get type equivalence, but you can close if you also use
inheritance.

template <BASE, typename T1, typename T2>
class Coolness<BASE, Coolness<T1, T2>, void>
: public Coolness<BASE, T1, T2>
{
typedef Coolness<T1, T2> Super1;
typedef Coolness<BASE, T1, T2> Base;

/* These constructors may or may not make any sense
for Coolness.
*/
Coolness(const BASE& b, const T1& t1, const T2& t2)
: Base(b, t1, t2) {}
Coolness(const BASE& b, const Super1& s)
};

Any template instantiations which have a 1 or 2 arg Coolness as the
second parameter, e.g. 'Coolness<string, Coolness<Coolness<string>,
string> >', will use the specialization. Note that the inner
Coolness-es in the example ('Coolness<string>' and
'Coolness<Coolness<string>, long>') do not use the specialization.
However, 'Coolness<string, Coolness<string, Coolness<string> > >' has
2 Coolness-es which do use the specialization.

Kanenas
Jul 23 '05 #2

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...
9
by: Philip Lawatsch | last post by:
Hi I'd like to implement some kind if type traits myself, but I have to support broken compilers (like visual studio) that do not support Partial Specialization. My first shot was something...
2
by: SainTiss | last post by:
Hi, If you've got a template class with lots of methods, and then you've got a type which works with the template, except for one method... What you need to do there is specialize the...
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...
7
by: Jon Slaughter | last post by:
#pragma once #include <vector> class empty_class { }; template <int _I, int _J, class _element, class _property> class RDES_T {
6
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
9
by: Greg | last post by:
Hi, I would like to specify behavior of a class member relatively to template implemetation. It works in usual cases but it seems to fail with to templates when one of the two is specified... ...
7
by: er | last post by:
hi, could someone please help with this code? template<unsigned int N,unsigned int M> class A{ public: A(); };
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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...

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.