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]
284 questions
94
votes
6 answers
C++ function template partial specialization?
I know that the below code is a partial specialization of a class:
template
class MyClass {
…
};
// partial specialization: both template parameters have same type
template
class MyClass {
……
![](../../users/profiles/163394.webp)
Narek
- 35,407
- 69
- 202
- 359
90
votes
4 answers
Why function template cannot be partially specialized?
I know the language specification forbids partial specialization of function template.
I would like to know the rationale why it forbids it? Are they not useful?
template void f() {} //allowed!
template<> void f
![](../../users/profiles/415784.webp)
Nawaz
- 327,095
- 105
- 629
- 812
86
votes
7 answers
How to do template specialization in C#
How would you do specialization in C#?
I'll pose a problem. You have a template type, you have no idea what it is. But you do know if it's derived from XYZ you want to call .alternativeFunc(). A great way is to call a specialized function or class…
user34537
49
votes
4 answers
Tag dispatch versus static methods on partially specialised classes
Suppose I want to write a generic function void f(), which does one thing if T is a POD type and another thing if T is non-POD (or any other arbitrary predicate).
One way to achieve this would be to use a tag-dispatch pattern like the standard…
![](../../users/profiles/235825.webp)
Peter Alexander
- 50,304
- 10
- 114
- 163
39
votes
2 answers
Why is it disallowed for partial specialization in a non-type argument to use nested template parameters
I have this code
template
struct A;
template
struct A {
/* ... */
};
// should work
A<25> a;
That is, for numbers N that are divisible by 5, the compiler should use the partial specialization. But the…
![](../../users/profiles/34509.webp)
Johannes Schaub - litb
- 466,055
- 116
- 851
- 1,175
38
votes
5 answers
"invalid use of incomplete type" error with partial template specialization
The following code:
template
struct foo {
void bar();
};
template
void foo ::bar() {
}
gives me the error
invalid use of incomplete type 'struct foo'
declaration of 'struct foo
![](../../users/profiles/112.webp)
Jesse Beder
- 30,017
- 18
- 97
- 140
32
votes
0 answers
What does six dots mean in variadic templates?
The following are some partial specializations for std::is_function from libstdc++'s :
/// is_function
template
struct is_function
: public false_type { };
template
…
![](../../users/profiles/498284.webp)
chys
- 1,401
- 10
- 15
29
votes
4 answers
(Partially) specializing a non-type template parameter of dependent type
Maybe I'm tired, but I'm stuck with this simple partial specialization, which doesn't work because non-type template argument specializes a template parameter with dependent type 'T':
template struct X;
template …
![](../../users/profiles/2644390.webp)
iavr
- 7,277
- 1
- 13
- 50
27
votes
2 answers
Template partial specialization for integral non-type parameters and non-integral non-types, difference between g++ and clang
The following is a simple template partial specialization:
// #1
template
struct foo {
static const char* scenario() {
return "#1 the base template";
}
};
// #2
// partial specialization where T is unknown…
![](../../users/profiles/2085626.webp)
Amir Kirsh
- 8,021
- 22
- 43
22
votes
2 answers
Multiple SFINAE class template specialisations using void_t
Are multiple class template specialisations valid, when each is distinct only between patterns involving template parameters in non-deduced contexts?
A common example of std::void_t uses it to define a trait which reveals whether a type has a member…
![](../../users/profiles/2023370.webp)
user2023370
- 9,597
- 5
- 41
- 74
20
votes
2 answers
Partial specialization of function templates
Does anyone know whether, in C++11, function templates can be partially specialized?
![](../../users/profiles/207177.webp)
There is nothing we can do
- 21,267
- 27
- 92
- 184
20
votes
2 answers
Get the signed/unsigned variant of an integer template parameter without explicit traits
I am looking to define a template class whose template parameter will always be an integer type. The class will contain two members, one of type T, and the other as the unsigned variant of type T -- i.e. if T == int, then T_Unsigned == unsigned int.…
![](../../users/profiles/230575.webp)
Blair Holloway
- 14,231
- 1
- 27
- 28
17
votes
2 answers
What are the 6 dots in template parameter packs?
While looking at this question I found myself in the cpp reference site where I noticed a strange and new to me syntax :
template
struct is_function : std::true_type {};
Yep, 6 dots ! Initially…
![](../../users/profiles/4224575.webp)
Lorah Attkins
- 3,879
- 2
- 22
- 52
13
votes
1 answer
Partial template specialization ambiguity
I cant see why the statement in main is ambiguous.
template struct X
{ void f() { cout << "Primary template" << endl; } };
template struct X
{void f() { cout << "Partial specialization 1" <<…
![](../../users/profiles/1116459.webp)
user1116459
- 133
- 6
13
votes
2 answers
Partial specialisation of member function with non-type parameter
I have a template class with both a type and a non-type template parameter. I want to specialize a member function, what I finding is, as in the example below, I can do a full specialization fine.
template
struct foo
{
…
![](../../users/profiles/427984.webp)
Eoin
- 1,568
- 9
- 19