Hi,
From what I've read in several places, it seems that explicit specialization
of member functions of class templates is allowed, but partial
specialization isn't:
template<class T, class R> class A {
void foo();
}
template <>
void A<int,double>:: foo() {} // allowed
template<class T>
void A<T,double>::fo o() {} // forbidden
However, when looking for justification in the ISO standard (final draft,
1996), it seems the first isn't explicitly allowed in there, and neither is
the second explicitly forbidden, even though the first seems to be used in
an example in 14.5.4.3
So does anyone know what the story is then? Does the standard really
allow/forbid this or not?
Thanks,
Hans 4 2587
"SainTiss" <st***@gmx.ne t> wrote... From what I've read in several places, it seems that explicit
specialization of member functions of class templates is allowed, but partial specialization isn't:
template<class T, class R> class A { void foo(); }
template <> void A<int,double>:: foo() {} // allowed
template<class T> void A<T,double>::fo o() {} // forbidden
No, not forbidden. You just have to partially specialise the class
template as well, before you attempt to define the member. 14.5.4.3/1.
However, when looking for justification in the ISO standard (final draft, 1996), it seems the first isn't explicitly allowed in there, and neither
is the second explicitly forbidden, even though the first seems to be used in an example in 14.5.4.3
So does anyone know what the story is then? Does the standard really allow/forbid this or not?
Both are allowed. A partial specialisation of a member requires
the same partial specialisation of the enclosing template to exist.
At least that's how I read the Standard.
Victor
Victor Bazarov wrote: No, not forbidden. You just have to partially specialise the class template as well, before you attempt to define the member. 14.5.4.3/1.
"The template argument list of a member of a class template partial
specialization shall match the template argument list of the class template
partial specialization. A class template specialization is a distinct
template."
Is this why you conclude that the partially specialised class needs to be
defined before its member is defined? That's not really clear, is it?
Additionally, that doesn't explain at all why it *is* allowed for an
explicitly specialised class...
Is the standard really this unclear about this?
Thanks,
Hans
"SainTiss" <st***@gmx.ne t> wrote... Victor Bazarov wrote:
No, not forbidden. You just have to partially specialise the class template as well, before you attempt to define the member. 14.5.4.3/1. "The template argument list of a member of a class template partial specialization shall match the template argument list of the class
template partial specialization. A class template specialization is a distinct template."
Is this why you conclude that the partially specialised class needs to be defined before its member is defined? That's not really clear, is it?
I am not sure about clarity (or lack thereof). A partial specialisation
is a whole different template, and its members know nothing about the
members of the original template, whereas a full specialisation of
a member _relies_ on the implicit instantiation of the original template.
That would be the main difference, I think.
Additionally, that doesn't explain at all why it *is* allowed for an explicitly specialised class...
Because a full specialisation causes an implicit instantiation of the
original template (I am still looking for the standard phrasing on that). Is the standard really this unclear about this?
For more clarification of the Standard and why it's so unclear I strongly
recommend asking in comp.std.c++.
Victor
Victor Bazarov wrote: I am not sure about clarity (or lack thereof). A partial specialisation is a whole different template, and its members know nothing about the members of the original template, whereas a full specialisation of a member _relies_ on the implicit instantiation of the original template. That would be the main difference, I think.
Additionally, that doesn't explain at all why it *is* allowed for an explicitly specialised class... Because a full specialisation causes an implicit instantiation of the original template (I am still looking for the standard phrasing on that).
That would indeed be a satisfactory explanation, if it is backed by the
standard. So I'm looking into that as well, but although it is possible to
interpret certain parts of it in that way, so far I too failed to find a
part which clearly justifies this.
Thanks,
Hans Victor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: SainTiss |
last post by:
Hi,
I've been looking into the standard for a clear statement on whether partial
specialization of member functions of class templates is allowed or not.
14.7.3/4 says that explicit specialization of a member function is legal,
but doesn't state that partial specialization is not.
One might argue that the standard indicates that partial specialization
implies a distinct template, and therefore defining a member function
|
by: Dave |
last post by:
Hello all,
I am trying to create a full specialization of a member function template of
a class template. I get the following errors:
Line 29: 'foo<T1>::bar' : illegal use of explicit template arguments
Line 29: 'bar' : unable to match function definition to an existing
declaration
What am I doing wrong?
|
by: Vaclav Haisman |
last post by:
Hi,
today a guy came to #C++@IRCNet and during discusion he showed this piece of
code:
template<bool tswitch=false>
class clstmp
{
|
by: Levent |
last post by:
Hi,
Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1):
#include <iostream>
template<class T, unsigned N>
struct Foo {
void func();
};
template<class T, unsigned N>
|
by: Nicolas Fleury |
last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment
welcomed (even about English mistakes).
PEP: XXX
Title: Specialization Syntax
Version: $Revision: 1.10 $
Last-Modified: $Date: 2003/09/22 04:51:49 $
Author: Nicolas Fleury <nidoizo at gmail.com>
Status: Draft
Type: Standards Track
| |
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:
|
by: Joseph Turian |
last post by:
Hi,
What is the correct syntax to get the bar<T>::f<int, unsigned>()
function to compile in the following fragment?
Thanks,
Joseph
class foo {
|
by: stephen.diverdi |
last post by:
Can anyone lend a hand on getting this particular template
specialization working? I've been trying to compile with g++ 4.1 and
VS 2005.
//------------------------------------------------------------------
// my regular glass
class A { };
// my templated class
|
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
trying to use from an executable, compile using gcc 4.1.2. Everything
works fine until I try specializing one of the static member function
templates in a non-template class. I have a feeling I'm messing up
something obvious so before I post a...
|
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,...
|
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...
| |
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |