Questions tagged [partial-specialization]

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.

316 questions
3
votes
1 answer

CPP templated member function specialization

I'm trying to specialize the member function moment() only (not the hole class) like this: template class AbstractWavelet { public: [...] template const typename T::scalar moment(const int i, const int…
Manuel
  • 801
  • 3
  • 8
  • 20
3
votes
2 answers

C++: Partial template specialization

I'm not getting the partial template specialization. My class looks like this: template class DaubechiesWavelet : public AbstractWavelet { // line 14 public: static inline const tVector waveletCoeff() { …
Manuel
  • 801
  • 3
  • 8
  • 20
3
votes
4 answers

How to read the template partial specialization?

Suppose the following declaration: template struct MyTemplate; The following definition of the partial specialization seems to use the same letter T to refer to different types. template struct MyTemplate {}; For…
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68
3
votes
4 answers

partial template member specialization

Given the following definitions: template class A { public: void f(); }; template void A::f() {} template class B {}; How would I partially specialize A>::f, i.e. f for some B? I'm basically…
regnirpsj
  • 97
  • 6
3
votes
3 answers

Allow member function for a specific type only

I am using C++ and templates - but I need to allow using a member function for a specific type and prevent other types from using this function. For example: I want this class to have print() for all types but have foo() for just type int. How can I…
Youssef Emad
  • 319
  • 2
  • 13
3
votes
2 answers

How can I use std::decay when partially specializing a type trait?

I made these type traits to determine if the type is a dynamic container, but recently ran into confusion when a reference to a vector didn't return true. template struct is_dynamic_container { static const bool value =…
Jonathan
  • 752
  • 1
  • 9
  • 19
3
votes
4 answers

Partial template specialization: matching on properties of specialized template parameter

template class A { // Use Y::Q, a useful property, not used for specialization. }; enum Property {P1,P2}; template class B {}; class C {}; Is there any way to define a partial specialization of A such that…
3
votes
2 answers

Specialisation for template class constructor

I am new to templates in C++. Can anyone explain why my specialised constructor never gets executed. It works when I remove the const and reference operator. #include #include using namespace std; template class…
3
votes
3 answers

specializing functions on stl style container types

If i have a type T, what is a useful way to inspect it at compile time to see whether its an STL-style container (for an arbitrary value type) or not? (Assumption: pointers, reference, etc. already stripped) Starting code: template //…
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
3
votes
1 answer

partial specialization for iterator type of a specified container type

I have a template struct, which accepts a Iterator type for the template argument. now I need to specialize that class for iterators of different containers. I have tried with std::vector template struct AC…
Frahm
  • 805
  • 2
  • 9
  • 16
3
votes
1 answer

Template specialization and plain old functions

I have just a simple question, check this code please: template < typename A > void foo( A a ) { cout<<"1\n"; }; template< > void foo( float a ) { cout<<"2\n"; } void foo( float a ) { cout<<"3\n"; } int main() { foo( 1.0f…
fjanisze
  • 1,234
  • 11
  • 21
3
votes
2 answers

c++ partial specialization: How can I specialize this template to this template?

#include using namespace std; template class A { public: void taunt() { cout << "A"; } }; template class A { public: void taunt() { cout << "B"; } }; class B {}; class C {}; int main…
user52343
  • 773
  • 1
  • 7
  • 19
2
votes
2 answers

Why doesn't my program work when I try to partially specialize a function template?

I am an beginner in template metaprogramming trying to implement generation of multiple versions of similar but slightly different code: #include enum Type { a1, a2 }; enum Style { b1, b2 }; template void…
2
votes
4 answers

Force compile time error when specialized template function is invoked

I have a template function. It has well defined semantics so long as the argument is not a pointer type. If someone calls this function passing an argument of type pointer I want to force a compile time error. I have no trouble writing the…
John Yates
  • 1,027
  • 1
  • 7
  • 18
2
votes
1 answer

Partial class template specialization not considered neither by GCC or CLang

Given this simple example: template class make_it { }; template class make_it { }; make_it I would expect to be able to use it both as make_it and make_it but the example template…