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

Friend explicit specialization of function template and ADL

Why in the following the partial specialization is not selected by ADL? template void func1(T&){ // selected ... } namespace first{ template struct foo{ friend void func1<>(foo&){ // expected …
Jans
  • 11,064
  • 3
  • 37
  • 45
0
votes
1 answer

C++ template specialisation friend iterator error: invalid use of incomplete type

For a project I'm working at, I've created a C++ library that encapsulates data structures. For each data structure, I've created custom iterators to navigate through data elegantly. Everything went fine until I've tried template specialization on…
0
votes
0 answers

Explicit Template Specialization With Enumerated Types

I have a class whose implementation differs (slightly) depending on a said multiplier. Basically, it will ultimately be a serial data packet. When placed in ASCII mode, the width of a number of bit-fields will double and those fields will differ in…
audiFanatic
  • 2,296
  • 8
  • 40
  • 56
0
votes
1 answer

partial class template specialisation for std::vector of fundamental types

I would like to partially specialise a class template for std::vector containing fundamental types. My approach looks like this, but does not compile #include #include #include #include template
Tobias Hermann
  • 9,936
  • 6
  • 61
  • 134
0
votes
2 answers

Problem with template specialization and template template parameters

I have a class Helper: template E> class Helper { ... }; I have another class template, Exposure, which is to inherit from Helper while passing itself as the template template parameter E. I also need to…
amc
  • 349
  • 3
  • 16
0
votes
1 answer

Is it legit to specialize variadic template class inside other template class

Consider a code: #include template struct outer { template struct inner { static constexpr bool value = false; }; template struct inner { static…
W.F.
  • 13,888
  • 2
  • 34
  • 81
0
votes
2 answers

How to specialize template pack?

I have the following code, which tries to convert a binary number (passed as a list of booleans, least-significant first, variable lenght) into a decimal number: #include using namespace std; template int bin_to_dec(int…
0
votes
2 answers

Instantiating the templated function using variables

I have three pointers within a class, each of which are instantiation of a templated structure. I am trying to retrieve either of them using a get<>() method whose return type differs accordingly. //Example program #include #include…
ZincFur
  • 49
  • 9
0
votes
1 answer

C++ template specialization rvalue

I'm learning C++ and have a little problem with template specialization. I need to call Variable.Set() a lot so, I made the function take in references so it doesn't spend a lot of time copying the string. But then the problem I have is…
Budskii
  • 109
  • 7
0
votes
3 answers

C++ invalid conversion from 'char' to 'const char*' in strcmp() within a template specialization

I am having trouble with using strcmp() for a const char* array inside a template specialization. In my script I want to sort several array's from large values/length to smaller ones. It works for an integer and float array however it does not work…
user_537
  • 161
  • 1
  • 1
  • 11
0
votes
1 answer

Value type deduction from non-type template parameter

I'm currently trying to implement a small template which deduces the type needed to store a certain number of bits given as template parameter: template class Register { public: unsigned long type; }; Furthermore I'm trying…
fhw72
  • 1,066
  • 1
  • 11
  • 19
0
votes
2 answers

The template parameter of my partial template specialization is not deducible

Please consider the following code snippet: template class vector_expression {}; template class vector : public vector_expression> { public: using value_type = typename…
0xbadf00d
  • 17,405
  • 15
  • 67
  • 107
0
votes
2 answers

C++ Specialized constructor of class without template arguments (skip angle brackets)

I have the following template function: template T test_function(T arg) {return arg;} I can create a specialized version of this for integers with: template<> int test_function(int arg) {return arg;} This is practical if I use this…
donald
  • 170
  • 4
0
votes
2 answers

Explicit function template specialization picks the wrong specialization

I have 2 functions inside a class, one is the default specilization of the operator+= which expects a function of some sort, whilst the second specilization expects an EventHandler, here is the implementation: template
0
votes
0 answers

prevent c++ template specialization issues with include cleanup

I am helping with some effort of improving the build speed of a big c++ project. One of the issues is that different set of includes my result in different execution code if template specializations are involved - based on if they are visible or…
gsf
  • 6,612
  • 7
  • 35
  • 64