Partial template specialization is a particular form of class template specialization. Usually used in reference to the C++ programming language, it allows the programmer to specialize only some arguments of a class template, as opposed to explicit specialization, where all the template arguments are provided.
Questions tagged [partial-specialization]
316 questions
5
votes
2 answers
Better pattern for partial specialization disambiguation precedence chain?
Consider the following series of partial specializations:
template
struct foo {
void operator()() const { cout << "unspecialized" << endl; }
};
template
struct foo

Daisy Sophia Hollman
- 6,046
- 6
- 24
- 35
5
votes
4 answers
optional range check based on template parameter
Let's say i have a class that simply performs addition for any type T. I want to add an optional range check (based on a template parameter of type bool), that will check whether the result of the addition belongs in a given range, or else it will…

xnth
- 156
- 1
- 8
5
votes
1 answer
Partial specialization with reference template parameter fails to compile in VS2005
I have code that boils down to the following:
template struct Foo {};
template & I> struct FooBar {};
////////
template struct Baz {};
template & I>
struct Baz<…

Blair Holloway
- 15,969
- 2
- 29
- 28
5
votes
1 answer
Static table generation works with GCC but not clang; is clang bugged?
I wrote some code once upon a time that generated a static table/array at compile time for some template metaprogramming (the idea is that C-style strings can be built at compile time (they're just char arrays)). The idea and the code is based off…

Cornstalks
- 37,137
- 18
- 79
- 144
5
votes
3 answers
C++ specialize template class function without duplicating code
I want to write 5 different classes, each of which has many member functions which are exactly the same, except of one, which is special for each class. Can I write this avoiding code duplication?
Regards,
Aleksejs
Below is a very shortened version…

Aleksejs Fomins
- 688
- 1
- 8
- 20
5
votes
2 answers
trouble with partial template specialisations
I have the following class structure
// file foo.h:
struct foo_base
{ ... }
template struct foo : foo_base
{ ... };
template
using is_foo = std::is_convertible;
template struct…

Walter
- 44,150
- 20
- 113
- 196
5
votes
2 answers
c++ partial specialization of template class member functions
There do appear to be a few closely related questions, but I'm struggling to work out how to apply their solutions.
I have a traits class, shown below, for manipulating matrices that I am using with boost::numeric:ublas::matrix (amongst other matrix…

Rai
- 1,328
- 11
- 20
5
votes
3 answers
What should I do instead of partial specialization of function templates?
I want to write the following:
template void foo() {
/* code for the general case */
}
template void foo() {
/* partially specialized code - for any kind of T, but when S is MySType */
}
or,…

einpoklum
- 118,144
- 57
- 340
- 684
5
votes
1 answer
Partial specialization of member function
Possible Duplicate:
“invalid use of incomplete type” error with partial template specialization
Why is it that I can do this:
template
struct A
{
void foo(int);
};
template <>
void A::foo(int)
{
}
but not this:
template…

HighCommander4
- 50,428
- 24
- 122
- 194
5
votes
2 answers
What is wrong with partial template specialization?
I am writing a templated class with one type paramenter and one boolean, here is the code:
template
class A
{
private:
T* ptr;
public:
A();
};
template
A::A()
{
ptr = 0xbaadf00d;
}
int…

Serge
- 1,027
- 14
- 21
4
votes
5 answers
C++: partial function specialization for void not allowed - alternative solution?
I think I understand by now why partial function templates are considered confusing and unnecessary, and are thus not allowed by the C++ standard. I would however appreciate some help with re-phrasing the following function w/o partial…

Peer Gynt
- 55
- 5
4
votes
2 answers
How to specialize a complex template with inheritance - C++
I can't seem to find the right syntax to specialize this template :
template
class TSin : public BasicTween

Bill Kotsias
- 3,258
- 6
- 33
- 60
4
votes
1 answer
How to check if a template argument is of a particular templated type (multiple type parameters)
I asked a question yesterday (How to find out if a type is a templated type of any type?) about how to check for a particular template argument when that argument is a templated class of any type. And the solution was something like this:
template…

Zebrafish
- 11,682
- 3
- 43
- 119
4
votes
1 answer
Template parameters not used in partial specialization
I have the following code:
template >
class Carray {
// ...
typedef T* pointer;
typedef pointer iterator;
// ...
};
Now I'm trying to do partial specialization for iterator_traits.…

orlp
- 112,504
- 36
- 218
- 315
4
votes
2 answers
Specializing a template for a container of type T
Given I have a template setup to do something on a type such as...
template
class SimpleTemplate
{
private:
T m_obj;
public:
void operator()() { m_obj.DoSomething(); }
};
And I want to handle the case where I have a collection of…

Matthew Cotton
- 65
- 5