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
9
votes
1 answer
clang/gcc inconsistency in class specialization
I came across this issue while trying to specialize tuple_size/tuple_element for a custom class in C++17 for structured binding.
Below code compiles in GCC, but not in clang (both trunk versions, see below link).
#include…

ofo
- 1,160
- 10
- 21
9
votes
1 answer
Partial Specialization of Variable Templates
I know that I can partially specialize class templates, and I know that I cannot partially specify function templates.
What about variable templates? I can't find documentation on whether they can be partially specialized.

Jonathan Mee
- 37,899
- 23
- 129
- 288
9
votes
1 answer
Partial template specialization with mismatching `int` and `size_t` not compiling
With reference to the following code
#include
#include
template
struct Wot;
template
struct Wot> {};
int main() {
assert(sizeof(Wot>) ==…

Curious
- 20,870
- 8
- 61
- 146
9
votes
4 answers
template partial specialization: How can code duplication be avoided?
When a template is fully specialized, a member function does not need to be duplicated. For example, in the following code, foo() is written only once.
#include
template
class B
{
public:
void foo(); …

Gidfiddle
- 111
- 4
9
votes
0 answers
Partial specialization and friendship
Suppose you have class A like this:
template
class A;
And class B like this:
template
class B;
And now you want both classes be friends when T is the same type, is this possible?
So for example A is…
user3624760
9
votes
2 answers
C++ Templates: Partial Template Specifications and Friend Classes
is it possible to somehow make a partial template specification a friend class? I.e. consider you have the following template class
template class X{
T t;
};
Now you have partial specializations, for example, for pointers
template…

gexicide
- 38,535
- 21
- 92
- 152
8
votes
2 answers
Determining whether a type is a class type?
In Chapter 19.8.4 of the book "C++ Templates - The Complete Guide - Second Edition", the authors show how one can determine if a type is a class type in compile-time:
#include
#include
using namespace std;
template…

Benji Mizrahi
- 2,154
- 2
- 23
- 38
8
votes
3 answers
Partial specialization of double-templated method fails
There is the template class List.
template
class List
{
public:
template
void load ( const char *file);
...
};
template
template

Robo
- 311
- 5
- 10
8
votes
2 answers
why SFINAE (enable_if) works from inside class definition but not from outside
Very weird problem I've been struggling with for the past few hours (after solving 5-6 other issues with SFINAE as I'm new to it). Basically in the following code I want to have f() working for all possible template instantiations, but have g()…

Otringal
- 131
- 7
8
votes
1 answer
Is it legal to perform partial in-class specialization of a member template class in derived class
It is continuation of this question. I am specifically interested if the partial specialization of a member class like this:
struct FooParent {
template
struct Bar{ };
};
struct Foo: FooParent {
template
struct…

W.F.
- 13,888
- 2
- 34
- 81
7
votes
1 answer
Exact rules for matching variadic template template parameters in partial template specialization
While creating this answer for another question I came around the following issue. Consider this program (godbolt):
#include
#include
template
struct TypeChecker {
void operator()() {
std::cout << "I am…

Jakob Stark
- 3,346
- 6
- 22
7
votes
1 answer
partial template specialization
I have a scenario in which there is a template class
template
class Foo
{
typedef Y::NestedType Bar;
int A (Bar thing);
void B();
int C(X that);
// other stuff
};
and then I would like the A() method to have a…

Enrico Granata
- 3,303
- 18
- 25
7
votes
1 answer
C++ template-based "override" equivalent when partial-specializing?
I have a template class/struct that looks like this:
template
struct S
{
unsigned int operator()(T t, U u) const;
};
And I would like to make sure that specializations respect this interface.
Unfortunately, I can…

vdavid
- 2,434
- 1
- 14
- 15
7
votes
3 answers
Using SFINAE partial specialization without touching the primary template
I'm trying to specialize a struct template for multiple types at once using
SFINAE. I know that something like the following works:
#include
template
struct S {
void operator()() {
…

ibab
- 924
- 7
- 15
6
votes
1 answer
Is this partial class specialization buggy or is it a bug in clang or gcc?
template
struct Foo {
template
constexpr auto a_method();
};
template
template
constexpr auto Foo::a_method() {
return 42;
}
template <>
template
constexpr auto…

vladon
- 8,158
- 2
- 47
- 91