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
2
votes
1 answer
Why is std::function implemented as a partial template specialisation with an empty base declaration?
Consider the declarations for std::function:
template< class >
class function; /* undefined */
template< class R, class... Args >
class function;
[source: cppreference.com]
We have a non-specialised declaration of the template that…

saxbophone
- 779
- 1
- 6
- 22
2
votes
2 answers
force template specialization with an incomplete (partially specified) templated type
I am encountering some issues when I try to force template specialization with an incomplete (partially specified) templated type.
Let's consider this oversimplified example:
I have a template function declaration for which I provide forced…

Andrea Buzzelli
- 137
- 7
2
votes
4 answers
Adding new constructors to a specialised template class
I have a class defining an array of fixed length n, with some methods.
template
struct array_container{
/* some code here */
int array[n];
};
Let's say I want to add a constructor to array_container<3>, something along the lines…

user3257842
- 135
- 4
2
votes
1 answer
Partial specialization difference for C++14 versus C++17?
The code:
#include
#include
#include
template struct pfun;
template
struct…

Edward Diener
- 127
- 3
2
votes
0 answers
What is the difference when using std::enable_if<> with partial specialization vs the type?
The next level of template programming (beyond very simple use) has eluded me for months as I work on a specific project I've been working on. I've tried scores of methods, cutting and pasting from StackOverflow as well as trying to understand and…

rtillery
- 367
- 1
- 10
2
votes
0 answers
How does the C++ compiler pick between alternate template (partial) specializations?
In the code below the compiler chooses template overload B for Foo and overload A for all other types e.g. Foo. This seems to depend on whether the second template argument in overload B matches the specified default of void for that…

Ziffusion
- 8,779
- 4
- 29
- 57
2
votes
1 answer
C++ partial class template specialization over multiple parameters
I'm trying to essentially define a template class that represents a hardware peripheral, which has some remappable pins. Since the mapping is defined at compile (or actually hardware schematic drawing) -time, I'd like to bring these defines in via…

Timo
- 739
- 1
- 6
- 13
2
votes
1 answer
Why is the partial specialisation of a template template argument not working?
I am considering Class1, Class2, Class3.
Class2 and Class3 have a partial specialisation with int, so they are identical in their definition.
On the other hand, Class1 has a specialisation for Class3 and for a general template template with only…

Garo
- 111
- 7
2
votes
2 answers
Why isn't `std::hash` a customization point by overload as `std::begin`?
As the title says, std::begin, std::end, std::swap, etc, are very well known std "customization points" (functions meant to be found by ADL). However, std::hash is, I think, the only std behaviour customizable by the user that implies to (A) open…

ABu
- 10,423
- 6
- 52
- 103
2
votes
1 answer
What is the rationale behind disallowing partial specialization of function templates?
I know that function templates can't be partially specialized, but I would like to know the reason for that.
Is it going to be changed in any upcoming C++ standard?
UPDATE: I disagree that the above-mentioned answer does provide an answer to the…

beginpluses
- 497
- 2
- 9
2
votes
1 answer
partial template specialization for dynamic dispatch
I am attempting to write a dynamic dispatcher for a function that's templated on integer values (not on types). While I could either write a code generator or use a big macro chain to create the dispatcher source, it seems that a templated solution…

Mr Fooz
- 109,094
- 6
- 73
- 101
2
votes
2 answers
Inner class depending on a template argument
Consider next example :
#include
#include
template< int N, typename T >
struct B
{
struct C;
};
template< typename T >
struct B< 0, T >::C
{
typedef T type;
};
template< int N, typename T >
struct B< N, T >::C
{
…

BЈовић
- 62,405
- 41
- 173
- 273
2
votes
1 answer
Role of default template parameters in overload resolution of (partially specialized) class templates
This answer explains the behaviour of the following program:
template
struct FirstWins {
static constexpr int i = 1;
};
template
struct FirstWins {
static…

L. Bruce
- 170
- 7
2
votes
1 answer
C++ class template constructor making decision based on type
I found a similar question here but it does not specifically answer my question. I have a simple class template that only takes one parameter. It does not store any member variables and has no methods other than a simple constructor. Based on the…

Francis Cugler
- 7,788
- 2
- 28
- 59
2
votes
1 answer
Using directive and Partial Specialization
I have a templatized interface class, with a couple of implemented methods and a couple of virtual ones.
I need to specialize it in order to modify the signature of some methods, but others would remain the same.
Is there a way to bring the methods…

Svalorzen
- 5,353
- 3
- 30
- 54