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

How to properly create an array of member template function pointers via meta programming

I want to pre create an array of template member function pointers, which will be indexed using a variable determined at run time by another class. The template functions can then be specialized. This works in a non-template class, however I'm…
0
votes
1 answer

C++ specialization does not working

I began to learn the language (С++) this month. Specialization must return the address of the longest line. My code is not working. The compiler errors are not showing. #include #include using namespace std; template…
Kas Elvirov
  • 7,394
  • 4
  • 40
  • 62
0
votes
1 answer

Executing a specific function based on a std::string

I am trying to write a program that will execute a function based on a string I fetch from a database. Basically what I do is: // Create an enum enum AFunc{ invalidFunction, function2, function3 } // have a class handling the functions struct…
Flo Win
  • 154
  • 10
0
votes
1 answer

How to symmetrically implement serialize and deserialize template functions in C++

I want to write a serial of template functions to serialize and deserialize objects. I've finished the serialization part and everything works: #ifndef SERIALIZE_H #define SERIALIZE_H #include #include #include…
0
votes
1 answer

Implementation switching with fully-specialized aliases

I'm writing for a project that uses makefile rules to switch between GPU and CPU implementations. I'd like to present an interface to user code that automatically switches between implementations without having to write #ifdef GPU_MODE all over the…
AGML
  • 890
  • 6
  • 18
0
votes
1 answer

Specialize template from class to integer

I am playing with template specializations to learn their limits, and I was trying now not to specialize based on type, but using an integer parameter. But I am failing. For instance, a template template should be specialized to have T for…
0
votes
1 answer

Check whether a type is a template specialization or not

Given an arbitrary template class/struct, just like: template struct A {}; I would like to perform a fashion check (let's name it is_A) to determine whether an arbitrary type is a specialization of A or not, just…
plasmacel
  • 8,183
  • 7
  • 53
  • 101
0
votes
1 answer

Create template class based on run time bool value

How can I implement below? I'd like to "pre-create" 2 "Doer" template class instances for bool values. Am I stuck with virtuals? what would be most efficient way to do something like this? I'm aware of boost variant, but not sure if that's the…
0
votes
1 answer

Specializing inner template of templated class

So I have a templated Image class, for which I am trying to set up inline color-conversions. This is a simplification of the code that is vexing me: template class Image { /// ... template
0
votes
1 answer

How to specialize a static function of a class template?

When I tried to write something like this: #include template class A { public: static void doit(); }; template <> static void A::doit() { std::cout << "int" << std::endl; } template <> static void…
0
votes
0 answers

Function Template specialisation pass value from struct constructor to a helper struct's constructor

This could be an easy answer to what I am facing, but I have tried my best the search previous posts, but none directly maps to what I need. The code below has a master (bmGsNoSuff) and slave (bmGsNoSuffHelper) . The Idea is, I want to pass the…
Walker
  • 323
  • 1
  • 12
0
votes
2 answers

C++ Function Template specialisation by value ( -1 )

I am trying to do a total template specialisation which should execute the first block of code (suffixTry) if i > -1 else do nothing (termination condition) . Am not very sure how the last suffixTry template should be written. When compiling, the…
Walker
  • 323
  • 1
  • 12
0
votes
0 answers

Specialization after instantiation with in the context of pointers

take a look at the code below (this code is part of something bigger, I can not reproduce all of the code, but this is the idea). template class Obs { public: virtual ~Obs () {} virtual void process (T t) = 0; }; template…
Artur Pyszczuk
  • 1,920
  • 1
  • 16
  • 23
0
votes
1 answer

Specialize member function for stl container

I have a class like this: class Foo { ... template class container> void fillContainer(container &out) { //add some numbers to the container } ... } I did it this way to be able to handle…
Thomas Sparber
  • 2,827
  • 2
  • 18
  • 34
0
votes
1 answer

Specialize static template function of base class

I'm trying to specialize a static template function from a base class, and figured this was a good use case for a typedef/using statement. I can't seem to get it to work, though. Is this illegal, or is my syntax wrong? #include class…
user1481860
1 2 3
99
100