473,756 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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> LongAndBoolCool ness;

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 1510
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> LongAndBoolCool ness;

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<strin g, Coolness<Coolne ss<string>,
string> >', will use the specialization. Note that the inner
Coolness-es in the example ('Coolness<stri ng>' and
'Coolness<Cooln ess<string>, long>') do not use the specialization.
However, 'Coolness<strin g, 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
6861
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 18.3.1, 'Iseq'). I want the version for containers that he gives, but also to provide a specialization for construction from a pair<It,It> (eg because that is returned by equal_range()).
9
2545
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 like this: ----8<--- typedef char IsPODForListArrayTrue;
2
2542
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 template for your type. However, this requires you to copy the whole template, and change the method, which leads to code duplication... If there's only 1 template parameter, one can specialize the method
8
7689
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 specialize Music<Bach>, I expect that the original play() method is available in the specialization, but it is not. How can I fix this? -X
7
567
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
2765
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 no errors compiling this:
9
2784
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 assign() function really a specialization of the first assign() or is it an assign() overload? Thank you. -- Marek
9
1960
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... Exemple: template <class T, int Num> class A
7
2985
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
9455
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.