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

Partial deduction of template parameter using constructor

I have seen this asked before in several ways, and all the solutions are always the same: use a helper function or even use nested classes. For me, both of those solutions look clumpsy. So I wonder how come in the c++17/c++20 era there is not better…
Pablo
  • 557
  • 3
  • 16
0
votes
1 answer

Partial specialization of typedef

I want to have a type which is either a typedef or a class. Thus, something like this template< typename T > class A { }; template< typename T > using X< T, true > = T; template< typename T > using X< T, false > = A< T >; Obviously, this does not…
tommsch
  • 582
  • 4
  • 19
0
votes
2 answers

Content of class method determined by the template value

By using c++ 14 or c++11, do we have an elegant approach to do the following task? Number of members and type of operations are determined by the template input value 'count' template class show{ public: run(){ …
0
votes
0 answers

E0312 IntelliSense Cannot convert _Binder

I am trying to make an Event Handler system on my project, and it is already working as expected, but the IDE are accusing an error that I have no idea how to solve. As I said, everything is working, compiling and running normally, but I would like…
0
votes
1 answer

Partial specialization C++

Good day! I am trying to build a template class with its several partial specializations as follows: #include struct MainT {}; struct Foo {}; template struct Tensor {}; template struct Bar { using Sub =…
0
votes
2 answers

Partial specialization and const conundrum in C++11

A class template: template class MyTemplate; I want to partially specialize this class so that when X is a const type, Y is an int and that partial specialization code is chosen if I create an object such as: MyTemplate
0
votes
0 answers

Making sense of class parameter pack in variadic templates

template struct Tuple { }; template< typename T, typename... Rest // Template parameter pack > class Tuple { // Class parameter pack [1] T first; Tuple rest; …
Bruce
  • 33,927
  • 76
  • 174
  • 262
0
votes
1 answer

Is it possible to mix SFINAE and template specialisation?

Here is what I am roughly trying to achieve: // the declaration template struct ArgsEstimate; // specialisation for string, SFINAE would be overkill template struct ArgsEstimate { …
tinkerbeast
  • 1,707
  • 1
  • 20
  • 42
0
votes
1 answer

C++ Undeclared Identifier in Template Template Parameter

I have a C++ class that is templatized like so: template class MyClass; Where Operator can also be templatized itself into: template class MyOperator; Now, when I try to write…
0
votes
1 answer

std::enable_if in partial specialization method of a templated class in C++

I have the following code: template class Data { public: int size() const; private: T m_data; }; I want to implement the size() method using template specialisation methods. For a std::string it would look like this (in the…
0
votes
1 answer

C++ Templated class function that can detect std::vector

If I have a templated class, I can do the following to detect if a vector was passed: template struct is_vector { static const bool value=false; }; template struct is_vector> { static const bool value=true;…
Dosisod
  • 307
  • 2
  • 15
0
votes
0 answers

Inherit itself using partial specialization

I have a class A which defines a lot of functions and I want to create a partial specialization of A which defines some more functions. I've read about a class inheriting itself but only with full specialization. So template struct A { …
user7769147
  • 1,559
  • 9
  • 15
0
votes
3 answers

Is there a way to partially specialize a template with parameter packs for a recursive function?

I'm trying to make a print function in C++ that takes in variable numbers of arguments and prints them each on their own line, like: template void println(Ty cur_line, Types... other_lines) { std::cout << cur_line…
0
votes
1 answer

How to define static member variable from class template with specialization?

OK I have this code: // default implementation just uses a mutex to serialize access template struct kernport { static const bool atomic = false; // constructor kernport(T value=T()) { set(value); …
gct
  • 14,100
  • 15
  • 68
  • 107
0
votes
1 answer

Generating type conversion functions using templates and partial specialization

I want to generate type-safe conversions between two sets of types using templates. The base case looks like this: template struct ATraits {}; template struct BTraits {}; template <> struct ATraits { using AType =…