473,748 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Template partial specialization

Comeau compiler complains (too few arguments for class template "B") at line
***

#include <memory>

template<typena me T, size_t n>
struct A {};

template<typena me T, size_t n>
struct B;

template<typena me T>
struct B<T,2> {};

int main()
{
A<int,2> a;
B<float> b; // ***
}

What am I doing wrong?
--
Tom Tempelaere
Jul 22 '05 #1
4 1967
TT (Tom Tempelaere) wrote in
news:ix******** ************@ph obos.telenet-ops.be:
Comeau compiler complains (too few arguments for class template "B")
at line ***

#include <memory>

template<typena me T, size_t n>
struct A {};

Add a default here if that is what you want.

template<typena me T, size_t n = 3 >

template<typena me T, size_t n>
struct B;

template<typena me T>
struct B<T,2> {};

int main()
{
A<int,2> a;
B<float> b; // ***
}

What am I doing wrong?


Your declaring a default, so you can't use a default.

Either add a sutible default or change line *** to

B< float, 3 > b;

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
"Rob Williscroft" <rt*@freenet.RE MOVE.co.uk> wrote in message
news:Xn******** *************** ***********@195 .129.110.200...
TT (Tom Tempelaere) wrote in
news:ix******** ************@ph obos.telenet-ops.be:
Comeau compiler complains (too few arguments for class template "B")
at line ***

#include <memory>

template<typena me T, size_t n>
struct A {};

Add a default here if that is what you want.

template<typena me T, size_t n = 3 >


That is _not_ what I want to do.
template<typena me T, size_t n>
struct B;

template<typena me T>
struct B<T,2> {};

int main()
{
A<int,2> a;
B<float> b; // ***
}

What am I doing wrong?


Your declaring a default, so you can't use a default.


I am not declaring a default, I'm partially specializing a template class.
That has nothing to do with defaults!
Either add a sutible default or change line *** to

B< float, 3 > b;
That would make partial specialization totally unusable!

Do you actually know what partial specialization of a template class is?
HTH.

Rob.


Tom.
Jul 22 '05 #3
TT (Tom Tempelaere) wrote in
news:_j******** ************@ph obos.telenet-ops.be:
"Rob Williscroft" <rt*@freenet.RE MOVE.co.uk> wrote in message
news:Xn******** *************** ***********@195 .129.110.200...
TT (Tom Tempelaere) wrote in
news:ix******** ************@ph obos.telenet-ops.be:

[snip]
Add a default here if that is what you want.

template<typena me T, size_t n = 3 >
That is _not_ what I want to do.


Actually when you combine the default with the specialization, it
probably is, but you didn't say what you wanted to do.
> template<typena me T, size_t n>
> struct B;
>
> template<typena me T>
> struct B<T,2> {};
>
> int main()
> {
> A<int,2> a;
> B<float> b; // ***
> }
>
> What am I doing wrong?
Your declaring a default, so you can't use a default.


Whoops missed a *not* in the above, It should have been:

Your not declaring a default, so you can't use a default.
I am not declaring a default, I'm partially specializing a template
class. That has nothing to do with defaults!
Yes you are, but then you try to use the class as if you had
given it a default for its second paramiter.
Either add a sutible default or change line *** to

B< float, 3 > b;
That would make partial specialization totally unusable!


You seem to be confused about what specialization does.

There can be only one class or class-template named B, if its
a class-template say B< typename, size_t > then it takes 2
arguments, specialization *isn't* overloading.

From your code above:

B< int, 1 > b1; // will instantiate the the unspecialized template.

B< int, 2 > b2; // will instantiate the specialization.

Do you actually know what partial specialization of a template class
is?
:) Yes *I* do.
HTH.


Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4
"Rob Williscroft" <rt*@freenet.RE MOVE.co.uk> wrote in message
news:Xn******** *************** ***********@195 .129.110.205...
TT (Tom Tempelaere) wrote in
news:_j******** ************@ph obos.telenet-ops.be:
"Rob Williscroft" <rt*@freenet.RE MOVE.co.uk> wrote in message
news:Xn******** *************** ***********@195 .129.110.200...
TT (Tom Tempelaere) wrote in
news:ix******** ************@ph obos.telenet-ops.be:

[snip]
Add a default here if that is what you want.

template<typena me T, size_t n = 3 >


That is _not_ what I want to do.


Actually when you combine the default with the specialization, it
probably is, but you didn't say what you wanted to do.
> template<typena me T, size_t n>
> struct B;
>
> template<typena me T>
> struct B<T,2> {};
>
> int main()
> {
> A<int,2> a;
> B<float> b; // ***
> }
>
> What am I doing wrong?

Your declaring a default, so you can't use a default.


Whoops missed a *not* in the above, It should have been:

Your not declaring a default, so you can't use a default.
I am not declaring a default, I'm partially specializing a template
class. That has nothing to do with defaults!


Yes you are, but then you try to use the class as if you had
given it a default for its second paramiter.
Either add a sutible default or change line *** to

B< float, 3 > b;


That would make partial specialization totally unusable!


You seem to be confused about what specialization does.

There can be only one class or class-template named B, if its
a class-template say B< typename, size_t > then it takes 2
arguments, specialization *isn't* overloading.

From your code above:

B< int, 1 > b1; // will instantiate the the unspecialized template.

B< int, 2 > b2; // will instantiate the specialization.

Do you actually know what partial specialization of a template class
is?


:) Yes *I* do.


:-)) I think I got it all screwed up. You are correct.

I'm sorry for questioning you.

Thanks,
Tom.
HTH.


Rob.
--
http://www.victim-prime.dsl.pipex.com/

Jul 22 '05 #5

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()).
1
1736
by: BekTek | last post by:
I'm still confused about the template partial specialization which is used in many libraries.. due to lack of introduction for beginner.. Could you tell me about that in short? Thanks in advance..
1
2221
by: Kai-Uwe Bux | last post by:
Hi folks, I would like to know which clause of the standard rules out this: template < typename eval > struct recursive_template { typedef typename eval::enum_type Enum;
2
2151
by: lhr_cool_guy | last post by:
C++ doesn't allow partial specialization of function templates. I want to know why this is so? Is the concept of function template partial specialization not well defined? I have a case where I feel there is a genuine need for it. Please take a look and tell me if there is a workaround: template< class T, class allocator > class A { /* ... */
7
1699
by: melfar | last post by:
Hello group, Consider such a class hierachy: template<typename Type> class SomeConcreteUsefulClass {} template<typename Type, typename SomeUsefulClass> class BaseClass {}
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(); };
4
1417
by: George2 | last post by:
Hello everyone, About Template Partial Specialization, http://www.cprogramming.com/tutorial/template_specialization.html sometimes in real case like below, http://www.sgi.com/tech/stl/iterator_traits.html
0
9561
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...
0
9381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9332
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
8252
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...
1
6799
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
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
4608
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2217
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.