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
3
votes
1 answer
Partial template specialization over instantiated and uninstantiated template
I have the following two structs:
template
struct one { /* ... */ };
template typename T>
struct two { /* ... */ };
When I have example instantiated/uninstantiated templates like this:
template
struct…

Post Self
- 1,471
- 2
- 14
- 34
3
votes
0 answers
Friend alias template does not compile with clang
The code bellow compiles without a warning on GCC and issues an error with clang (any c++11 compatible versions of both clang and GCC).
Which compiler is right with respect to the standard?
Specifically, is it allowed to declare as friend a non…

Meatboy 106
- 196
- 7
3
votes
1 answer
undefined reference to full template specialization class member function, but not partial specialization
so i got an undefined reference error when using template explicit instantiation with full template class specialization, but the question is, partial template class specialization goes well without error.
code shows as below, do anyone know why?…

Niu Chong
- 39
- 6
3
votes
1 answer
Why can't Visual C++ partially specialize a class inside a template?
When I try to run this code in Visual C++ (2015)
template
struct outer
{
template
struct inner;
};
template
template
struct outer::inner { enum { value = 0 }; };
int main()
{
return…

user541686
- 205,094
- 128
- 528
- 886
3
votes
1 answer
C++ partial template specialization syntax
for primary template:
template class MyClass {...
with template specialization, what is the difference between
template class MyClass {...
and
template<> class MyClass {...

uray
- 11,254
- 13
- 54
- 74
3
votes
1 answer
something confusing about class template partial specialization & class member specialization
Here I define a class template Foo, specialize its member function, and then supply a partial specialization for that class:
// this is Foo_0
template
class Foo {
public:
void operator()() {
std::cout <<…

Dardai
- 93
- 6
3
votes
1 answer
c++ template specialization with std::enable_if not working
I've a simple primary function template that I want to partially specialize.
template< typename T >
void SetAttribute( const T& value )
{
static_assert( false, "SetAttribute: wrong type!" );
}
template<> void SetAttribute( const bool& value )…

Fred
- 596
- 1
- 6
- 19
3
votes
2 answers
Template partial specialization on bool
That's a really basic question I think, but I was'nt able to find an answer, even on StackOverflow. So sorry if you want to hit me when you'll read this.
I just want to do a partial specialization on bool value :
template < typename Object, bool…

Mathieu Van Nevel
- 1,428
- 1
- 10
- 26
3
votes
3 answers
Define partial specialization for some external template classes with restriction for template parameters
I have a class Foo and class Bar. They are wrappers over std::array.
Both of them have some derived classes.
template
struct Foo {
std::array data;
};
template
struct FooDerived : Foo…

Vladislav
- 394
- 1
- 14
3
votes
1 answer
C++ template partial explicit instantiation
Can we partially instantiate a C++ template explicitly?
template class
class MyClass {
...
};
template class MyClass; // not meant for specification
template class MyClass;
just like we can…

yuefengz
- 3,338
- 1
- 17
- 24
3
votes
1 answer
c++ member function specialisation of a class that has a template as a parameter
I am working on a template class Array, which accepts another template TRAITS as a parameter.
template
class Traits {
public:
typedef BASE BaseType;
typedef STRUCT Struct;
// .. More…

matejk
- 798
- 1
- 14
- 27
3
votes
2 answers
Template template partial specialization failure: "expected a class template"
This example code generates expected a class template, got std::pair <_T1, _T2>. I tried using struct Struct {};, but then parameters T and M become undeducible. How to avoid this?
template class>
struct…

Alex
- 1,165
- 2
- 9
- 27
3
votes
1 answer
May std::tuple_element double as a universal template argument retriever?
This question got me thinking. Sometimes it's useful to grab an actual argument from a class template specialization, if it fails to define a public typedef of the argument. In C++03 it's a sign of either bad template design, or contrary design…

Potatoswatter
- 134,909
- 25
- 265
- 421
3
votes
2 answers
Implement `to_xstring()` to unite `to_string()` and `to_wstring()`
Since the names of to_string() and to_wstring() differ, it's practically impossible to use them in generic functions. So, I'm planning to unite them with the following:
template
auto to_xstring(const T& x);
The question…

Lingxi
- 14,579
- 2
- 37
- 93
3
votes
2 answers
Which rules apply when an argument of partial specialization does not use any of its template parameters
n4567 [temp.class.spec.match]p2
A partial specialization matches a given actual template argument list if the template arguments of the partial specialization can be deduced from the actual template argument list (14.8.2).
template

stackcpp
- 1,275
- 7
- 15