Questions tagged [template-specialization]

Template specialization refers to programmer-generated explicit specialization of templates for specific types.

Templates refer to the ability to write code that works for any type satisfying the operations used within the class and/or function on that type. Template specialization refers to the ability for the programmer to explicitly change the code for a given type, either by a partial specializion of the template (in which a subset of parameters are specialized over), or a full specialization of the template (where all parameters are specialized).

1616 questions
0
votes
2 answers

C++ Calling template specialized function

I have the following piece of code. The code compiles fine: File A.h #include class B {}; class C {}; template class A { public: explicit A(T1 t1); template void foo(T1 t, T2 t2, T3 t3); …
gudge
  • 1,053
  • 4
  • 18
  • 33
0
votes
2 answers

partially specialize function template with no parameters

I think it's not possible but someone must know better... template T Read() //T is int, char, etc { return read(); } template std::array Read>() { return unique_read
Gam
  • 1,254
  • 1
  • 9
  • 18
0
votes
1 answer

Less verbose templated private static const member variable specialisation

So if I want to specialise: template class my_class{ private: static const std::string my_string; }; The only way I was able to do it was via template<> const std::string my_class::my_string = "the…
xvan
  • 4,554
  • 1
  • 22
  • 37
0
votes
2 answers

Specializing class template for any subclass of X without adding an additional type argument to the template

I need to specialize template< typename T, int Id > struct ValueTraits { // Default version static int getValue() { return 0; } }; for any subclass of some ConcreteClass as T: class ConcreteClass {}; struct ConcreteSub1: public…
dragonroot
  • 5,653
  • 3
  • 38
  • 63
0
votes
1 answer

Overriding template function in specialized daughter class

I have a templated class MatchBase with a function for the operator == as such template class MatchBase{ virtual bool operator ==(const MatchBase& m) const{ if(_v1 == m.getFirst() && _v2 == m.getSecond()){ …
Malcolm
  • 662
  • 7
  • 29
0
votes
1 answer

omit template parameter (for function pointer argument)

I'm writing template factory that stores function pointer to create user objects. I would like to support user Creation function with and without argument (for now, one or zero argument will do). (and i can't use boost or c11 unfortunately…
0
votes
0 answers

how to specalize class-member function template without class specialization

For example, i have such code: .h-file: template class Templ { public: template T foo (T t); }; .cpp-file: template template T Templ::foo (T t) { qDebug() << "Non-specialised…
DmitryU
  • 31
  • 4
0
votes
1 answer

template specialization inside class namespace

How to specialize a template defined in some external namespace in the body of my class? Concrete example using BGL which doesn't compile: class A { namespace boost { template struct container_gen
0
votes
2 answers

How to enforce template parameter class to derive from super with an anonymous template parameter

I have a couple of template classes template < class Cost > class Transition { public: virtual Cost getCost() = 0; }; template < class TransitionCl, class Cost > class State { protected: State(){ static_assert( …
A Frayed Knot
  • 476
  • 5
  • 20
0
votes
2 answers

How to specialize a function template with more than 1 parameter?

Consider the following templated member function: template void Node::connectEvent( const bool( N::*fn )( const P& ), N *inst ) { // Obtain unique event ID based on type. size_t eventId = typeid( E…
Paul Houx
  • 1,984
  • 1
  • 14
  • 16
0
votes
1 answer

Nested class template specialization not matched correctly + msvc internal error

This question consists of two parts, marked (A) through ...ahem... (C). template< unsigned a > struct Outer { /* (A) Provide a match if the template parameter of Inner is the same as Outer. Do something different in the general case…
0
votes
2 answers

specialized template for subclass

Have a simple example, with two questions related. Source code - 3 files: parent.h: #ifndef PARENT_H #define PARENT_H using namespace std; #include template class PARENT { public: class CHILD_DATA { …
Bob
  • 137
  • 1
  • 6
0
votes
0 answers

Can I disable a specialization of std::char_traits based on a boolean expression?

Using C++11 (or C++14), I'd like to specialize std::char_traits for unsigned char, but only if !std::is_same::value. (Since std::char_traits already exists.) So I currently have such a specialization, which begins like…
md5i
  • 3,018
  • 1
  • 18
  • 32
0
votes
2 answers

C++ template specialisation, but no match found

I have a deserialisation function. With templates, I'd like to be able to get the thing that I'm deserialising. In other words, I'd like a function that computes the serialised thing and another that handles deserialisation. If I name them…
jma
  • 3,580
  • 6
  • 40
  • 60
0
votes
1 answer

Nested class template full specialization versus partial specialization

The following code is giving me the compile error: error: explicit specialization in non-namespace scope 'struct Apply' template < > ^ #include struct Apply { template < typename ...BaseClasses> struct…
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64
1 2 3
99
100