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
6
votes
2 answers
How to define a specialized class method outside of class body in C++?
I have a template class A and its specialization for integral arguments. And both the class and its specialization declare the method foo(), which I would like to define outside of class bodies:
#include
template
struct A {…

Fedor
- 17,146
- 13
- 40
- 131
6
votes
3 answers
Partial specialization using Concepts
I was just reading the examples of C++20 Concepts. Now I am trying to create a function that will print out if the given type is a hash-table or not using concepts mixed with the partial-specialization. But unfortunately it doesn't work.
#include…

Mohit
- 1,225
- 11
- 28
6
votes
6 answers
Unrolling loops using templates in C++ with partial specialization
I'm trying to use templates to unroll a loop in C++ as follows.
#include
template< class T, T i >
struct printDown {
static void run(void) {
std::cout << i << "\n";
printDown< T, i - 1 >::run();
}
};
template<…

Ashley
- 829
- 1
- 5
- 16
6
votes
1 answer
class template partial specialization parametrized on member function return type
The following code, which attempts to specialize class template 'special', based on the return type of member function pointer types, results in a compile error with VC9:
template struct special {};
template struct…

Functastic
- 606
- 3
- 12
6
votes
3 answers
Partial class template specialisation for multiple types
I have a class which allows for a vector to be created holding any type or class. However I'd like to add additional functionality for numerical types.
template <>
class Vec : public VecBase
{
// == METHODS ==
public:
…

user7119460
- 1,451
- 10
- 20
6
votes
2 answers
C++: template to check if expression compiles
When writing template specialization with SFINAE you often come to the point where you need to write a whole new specialization because of one small not-existing member or function. I would like to pack this selection into a small statement like…

tly
- 1,202
- 14
- 17
6
votes
2 answers
Double-templated function instantiation fails
The following code:
template __global__ void myKernel(const T a[]);
template __global__ void myKernel(const T a[]) {
// implementation
}
Triggers the following error message:
error: an…

einpoklum
- 118,144
- 57
- 340
- 684
6
votes
2 answers
C++ template specialization for specific values
I have struct Opers with some arithmetic operations: mult(), div(), mod().
And I need to specialize template for certain values of n. Here is example for Opers<1>.
But, also I want to do specialization for n that are powers of 2 ( n = 2,4,8,16,…

takka
- 63
- 5
6
votes
1 answer
Partial template specialization of member function: "prototype does not match"
I'm trying to partially specialize a templated member function of an untemplated class:
#include
template
class Foo {};
struct Bar {
template
int fct(T);
};
template
int Bar::fct(Foo)…

Frank
- 64,140
- 93
- 237
- 324
6
votes
2 answers
ambiguous partial specializations with std::enable_if
I have a problem encountered at a condtion like below:
#include
#include
#define TRACE void operator()() const { std::cerr << "@" << __LINE__ << std::endl; }
template
struct check : std::true_type {};
template…

changsheng
- 101
- 1
- 6
6
votes
2 answers
Template compilation error in Sun Studio 12
We are migrating to Sun Studio 12.1 and with the new compiler [ CC: Sun C++ 5.10 SunOS_sparc 2009/06/03 ]. I am getting compilation error while compiling a code that compiled fine with earlier version of Sun Compiler [ CC: Sun WorkShop 6 update 2…

Jagannath
- 3,995
- 26
- 30
5
votes
2 answers
Template partial specialization with multiple template argument error
When I use template partial specialization on a class with one template argument, I can specialize a method like this:
#include
template< std::size_t Dim >
class Test
{
public:
int foo();
};
template< std::size_t Dim >
inline int Test<…

Philippe Cayouette
- 674
- 6
- 14
5
votes
1 answer
`template ` and partial class template specialization ordering
Consider:
#include
template
struct Tag {};
template
auto tag = Tag{};
template
struct SelectorImpl;
// 1
template
struct SelectorImpl

yuri kilochek
- 12,709
- 2
- 32
- 59
5
votes
0 answers
Partial specialization is not more specialized
To my surprise, I got an error, when I tried to compile this code with GCC 7.2.0.
Code:
#include
#include
#include
template struct increment;
template

SU3
- 5,064
- 3
- 35
- 66
5
votes
3 answers
C++ template partial specialization error
The following code is giving me a compilation error: class Q64 is not a valid type for a template constant parameter
template
INLINE T grid_residue(T amount) {
T rem = amount%(GRIDD);
if (rem > GRIDD/2) rem -= GRIDD;
return…
JP19