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
1 answer

SFINAE together with auto-deduced return type and variadic templates

In this topic, we learn how to use SFINAE together with auto/self-deduced return type: How do I use std::enable_if with a self-deducing return type? However, it seems I cannot apply any of the techniques when I'm also using a variadic template.…
Shaggi
  • 1,121
  • 1
  • 9
  • 31
0
votes
1 answer

using enable_if to specialize on return type from a base class

I'm porting a large code base to clang (builds with g++ and intel c++). Code similar to the following snippet compiles and works on g++ 4.8 - 6.2 but fails to compile with clang 3.8 and 3.9. The second invocation of the MinOp should (AFAICT) get…
Chris Morley
  • 891
  • 6
  • 16
0
votes
0 answers

Invoke std::hash() through constructor in unordered_map wrapper in C++

We are trying to set mHashCode either through template specialization of operator()(string in this case) or through the c'tor of HashFunction() by the user provided key(here, inKey). #include #include using namespace…
Foobar-naut
  • 123
  • 1
  • 1
  • 9
0
votes
2 answers

Partially specialize methods of variadic template classes

I want to write an unmarshaller to extract arguments stored in a msgpack array for individual arguments to a call of sigc::signal::emit(...). I tried this: template class MsgpackAdapter: public MsgpackAdapterBase { public: …
0
votes
1 answer

Fully specialize a template class with template constructor

I have a template class defined as follow : template class Matrix { public: Matrix(const float k = 0.0f) { for(unsigned int i = 0; i < N; ++i) for(unsigned int j = 0; j…
e.farman
  • 335
  • 2
  • 12
0
votes
1 answer

Counter gets bugged next time using the function

First of all I'm sorry for the title, couldn't explain it clearly using only one sentence.. I'm creating an object that has an array and a counter to count how many elements are inside the array at any time, but somehow, the counter loses its value…
0
votes
2 answers

Differentiating Specialized Structs based on signed-ness

I need to be able to differentiate between data types which have the same sizes but different signed-ness properties. An example follows, template struct alias; template<> struct alias{ using Type = unsigned…
nmd_07
  • 666
  • 1
  • 9
  • 25
0
votes
0 answers

How to combine type alias with the definition of full specialization?

I can combine type alias with class definition like this: using XX = struct AA { }; But how can I combine type alias with the definition of a full specialization? template < typename... > struct BB; using YY = template <> struct BB { }; //…
Vahagn
  • 4,670
  • 9
  • 43
  • 72
0
votes
1 answer

Specialization of operators inside template class between objects of different specialization of that class

I have the following problem/question: Suppose that i have a template class Couple which have two attributes x and y of type xobject. I can easily define the sum between Couple of the same class simply defining the sum element by element, if it is…
Nicola
  • 1
  • 1
0
votes
2 answers

how to do specialize a function template when template parameter is a class template?

For example template T make() { return T(); } and I want to specialize it when T is a class template A; template class A {}; template A make>() { ... }; Error in compilation: illegal use of explicit template…
user1899020
  • 13,167
  • 21
  • 79
  • 154
0
votes
0 answers

why template with 2 parameters can't be specialized the same as with one parameter

I recently came across this very weird problem: if we have a template class like the one below: template class A { public: void f(void); void g(void); }; and I want my f() function to be available for any type 'T', but I want…
0
votes
1 answer

pointer to incomplete class type is not allowed in a partial template class

I am modifying some existing code in a project. I have a template class Param and a partial specialized template class for parameters in a header file as below: template struct Param { static void add(ParameterCode code,…
masterop
  • 184
  • 1
  • 12
0
votes
0 answers

Default type conversion can't deduce template argument in SFINAE'd conversion operator

Consider the code below. My intention is to use a different conversion operator(implicit) depending on the template type argument of struct B. #include #include using namespace std; // just to simplify syntax template…
Kemal
  • 849
  • 5
  • 21
0
votes
1 answer

How to move template constructor specialization to cpp file?

I am aware of the reasons why the implementation of templates should go to the header. This question is about template specialization. As far as I understand, this setup should work. header: template class Foo { public: Foo(T value) { …
lyron
  • 246
  • 2
  • 7
0
votes
1 answer

Template specialization for destructor

I'm building a hashmap class that can have string keys and ints, bools, strings or pointers of different types as its values, and I want it to work. For the program I'm using it for I create the pointer and pass it into the hashmap. The problem…
Trevor
  • 955
  • 9
  • 16