Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > partial template specialization

Reply
Thread Tools

partial template specialization

 
 
Andrew Tomazos
Guest
Posts: n/a
 
      01-06-2012
template<class T, bool signedness>
void f2(T);

template<class T>
void f2<T, true>(T t)
{
... do something with signed integer
}

template<class T>
void f2<T, false>(T t)
{
... do something with unsigned integer
}

template<class T>
void f(T t)
{
f2<T,numeric_limits<T>::is_signed>(t);
}

Compiler says no partial specialization.

How do I do what I'm trying to do?
-Andrew.

 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      01-06-2012
Andrew Tomazos <(E-Mail Removed)> wrote:
> Compiler says no partial specialization.
>
> How do I do what I'm trying to do?


Support for partial specialization of functions was not in the old
C++ standard but is supported in the new one. If you want to make it
work, you'll have to start using a compiler (or compiler setting) that
supports the newer standard.
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      01-06-2012
Juha Nieminen wrote:

> Andrew Tomazos <(E-Mail Removed)> wrote:
>> Compiler says no partial specialization.
>>
>> How do I do what I'm trying to do?


Closest to what you are trying:
template<bool b> struct Help {
static ...
};
template<> struct Help<true> {
static ...
};
And call Help<...>::function(...) from your wrapper.

You could also use overloading and enable_if instead.

> Support for partial specialization of functions was not in the old
> C++ standard but is supported in the new one.


Really? I don't remember hearing of such a change, and gcc/clang still
reject partial specialization of functions.
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-06-2012
On 1/6/2012 4:21 AM, Juha Nieminen wrote:
> Andrew Tomazos<(E-Mail Removed)> wrote:
>> Compiler says no partial specialization.
>>
>> How do I do what I'm trying to do?

>
> Support for partial specialization of functions was not in the old
> C++ standard but is supported in the new one. [..]


In faint hopes that you're not confusing "partial ordering" for "partial
specialization", could you please quote the Standard on that? Thanks!

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      01-06-2012
Victor Bazarov <(E-Mail Removed)> wrote:
> On 1/6/2012 4:21 AM, Juha Nieminen wrote:
>> Andrew Tomazos<(E-Mail Removed)> wrote:
>>> Compiler says no partial specialization.
>>>
>>> How do I do what I'm trying to do?

>>
>> Support for partial specialization of functions was not in the old
>> C++ standard but is supported in the new one. [..]

>
> In faint hopes that you're not confusing "partial ordering" for "partial
> specialization", could you please quote the Standard on that? Thanks!


I was probably confusing it with default template parameters. My bad.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Template template partial specialization Hizo C++ 17 03-07-2011 08:09 AM
how to do partial specialization template for non member method template vj C++ 1 12-20-2010 11:57 AM
syntax problem for partial template specialization for a template class. toton C++ 1 12-28-2006 04:08 PM
template specialization overriding non-specialization? Joseph Turian C++ 2 04-16-2006 02:46 PM
template partial specialization Chandra Shekhar Kumar C++ 17 06-25-2003 03:35 PM



Advertisments