partial template specialization

A

Andrew Tomazos

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.
 
J

Juha Nieminen

Andrew Tomazos said:
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.
 
M

Marc

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.
 
V

Victor Bazarov

Andrew Tomazos said:
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
 
J

Juha Nieminen

Victor Bazarov said:
Andrew Tomazos said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top