473,661 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which function gets specialized?

I have this example:

template<class T(1)
void f( T );

template<class T(2)
void f( T* );
template< (3)
void f<>(int*);
Which of (1) and (2) does (3) specialize, and why?

Is the order just a matter of when the specialization is declared?
May 12 '07 #1
5 1642
desktop wrote:
I have this example:

template<class T(1)
void f( T );

template<class T(2)
void f( T* );
template< (3)
void f<>(int*);
Which of (1) and (2) does (3) specialize, and why?

Is the order just a matter of when the specialization is declared?
It's simpler: (2) is a partial specialization of (1), while (3) is a
specialization of (1). Note that there is no relationship between the
specializations , they are just different implementations . So, it makes
no sense to ask if (3) specializes directly (1) or the partial
specialization (2): it's just a specialization of (1).

Regards,

Zeppe
May 12 '07 #2
On May 13, 12:18 am, Zeppe
<z...@remove.al l.this.long.com ment.email.itwr ote:
desktop wrote:
I have this example:
template<class T(1)
void f( T );
template<class T(2)
void f( T* );
template< (3)
void f<>(int*);
Which of (1) and (2) does (3) specialize, and why?
Is the order just a matter of when the specialization is declared?
It's simpler: (2) is a partial specialization of (1), while (3) is a
specialization of (1). Note that there is no relationship between the
specializations , they are just different implementations . So, it makes
no sense to ask if (3) specializes directly (1) or the partial
specialization (2): it's just a specialization of (1).
There's no such thing as partial specialization of a function
template. (1) and (2) are two, independent function templates.

Partial ordering of function templates (§14.5.5.2) says that the
specialization (3) is for function template (2). This makes
sense, because the same partial ordering is used in overload
resolution, which means that in fact, (1) will never be called
with an int*.

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 12 '07 #3
James Kanze wrote:
On May 13, 12:18 am, Zeppe
<z...@remove.al l.this.long.com ment.email.itwr ote:
>desktop wrote:
>>I have this example:
>>template<clas s T(1)
void f( T );
>>template<clas s T(2)
void f( T* );
>>template< (3)
void f<>(int*);
>>Which of (1) and (2) does (3) specialize, and why?
>>Is the order just a matter of when the specialization is declared?
>It's simpler: (2) is a partial specialization of (1), while (3) is a
specializati on of (1). Note that there is no relationship between the
specialization s, they are just different implementations . So, it makes
no sense to ask if (3) specializes directly (1) or the partial
specializati on (2): it's just a specialization of (1).

There's no such thing as partial specialization of a function
template. (1) and (2) are two, independent function templates.
Whatever. The effect is that for a pointer (2) will be called instead of
(1), and, if there is no method to call (1) with pointer, it's the same
of a partial specialization, isn't it?

Regards,

Zeppe
May 12 '07 #4
On May 13, 1:24 am, Zeppe <z...@remove.al l.this.long.com ment.email.it>
wrote:
James Kanze wrote:
On May 13, 12:18 am, Zeppe
<z...@remove.al l.this.long.com ment.email.itwr ote:
desktop wrote:
I have this example:
>template<cla ss T(1)
void f( T );
>template<cla ss T(2)
void f( T* );
>template< (3)
void f<>(int*);
>Which of (1) and (2) does (3) specialize, and why?
>Is the order just a matter of when the specialization is declared?
It's simpler: (2) is a partial specialization of (1), while (3) is a
specialization of (1). Note that there is no relationship between the
specializations , they are just different implementations . So, it makes
no sense to ask if (3) specializes directly (1) or the partial
specialization (2): it's just a specialization of (1).
There's no such thing as partial specialization of a function
template. (1) and (2) are two, independent function templates.
Whatever. The effect is that for a pointer (2) will be called instead of
(1), and, if there is no method to call (1) with pointer, it's the same
of a partial specialization, isn't it?
No. In this case, it sort of acts like one, but partial
specialization of class templates and overloading of function
templates obey different rules in general, and it is better to
keep the vocabulary clean, and to not mix up the two.

You might want to reread section 13.7 of Vandevoorde and
Josuttis. The section carries the somewhat misleading title of
"Partial Specialization of Function Templates", but it explains
in detail the concrete differences between partial
specialization (of class templates) and overloading (of function
templates). (If you haven't already read the book, then you
definitly should. It is the definitive reference concerning
templates, and it is exceptionally well written.)

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

May 13 '07 #5
James Kanze wrote:
You might want to reread section 13.7 of Vandevoorde and
Josuttis. The section carries the somewhat misleading title of
"Partial Specialization of Function Templates", but it explains
in detail the concrete differences between partial
specialization (of class templates) and overloading (of function
templates).
I see. Really interesting reference, thanks for the suggestion!

Regards,

Zeppe
May 13 '07 #6

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

Similar topics

2
1200
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 the class template bar_impl, nested within foo. The template bar_impl is partially specialized outside of foo. My question is which specialization should be selected: the primary template or the partial specialization. Or does the program exhibit...
2
6190
by: Hartmut Sbosny | last post by:
Hello NG, I have a question. I have a header file with a function template and a fully specialized version of it, for instance //======== File "templ.hpp" ======== #include <iostream> // the general function template... template <class T>
16
16270
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
6
2127
by: bluekite2000 | last post by:
I have Vector<complex<float> > V(5); V.rand(); Vector<float> V1(V); //specialized function here to return norm(V). This works fine Vector<double> V2(5); V2.rand(); Vector<float> V3(V2);//error no matching function for call to norm(double)
9
8250
by: tropostropos | last post by:
On Solaris, using the Sun compiler, I get annoying warnings from the following code. The problem is that I am passing a C++ member function pointer to the C library function qsort. Is there a solution? Declaring the function extern "C" fails, because linkage declarations must be made at file scope. #include <stdlib.h> //for qsort template <class T> class Sorter
6
324
by: Ronald Mai | last post by:
In my opinion, Ellipsis might be in the middle, not only in leftmost or rightmost, so a placeholder approach can be much more flexible and convenient. Here is a reference implementation: _ = lambda x: x.pop(0) def partial(func, *args, **keywords): def newfunc(*fargs, **fkeywords):
7
9436
by: quarup | last post by:
I want to specialize a template function that lives inside a class, but am getting a compile error in VS.net 2003. Here's my code: template <class T> class A { public: template <class U> void f() const; };
1
1639
by: vectorizor | last post by:
Hello, I've got a template function: template <typename U, typename T> void func(ColourImage<U&input,GrayImage<T&out_r, GrayImage<T> &out_g, GrayImage<T&out_b); and I would like to specialize it for U = unsigned char. So I wrote
2
3717
by: Aarti | last post by:
Say I have a class template as follows template<typename T> class foo { public: void test(); }; template<typename T>
0
8432
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
8343
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
8855
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
8758
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...
0
8633
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 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...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
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.