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

Specialization of Member Function of a Template Class - on Linux using g++-4.7

I know from this thread - template class member function only specialization that if I specialize a class template, I need to specialize all the member functions. So, my rationale was that I would 'instantiate' a template class. (Not sure if its…
sskanitk
  • 475
  • 4
  • 11
  • 19
1
vote
1 answer

How to do a partial template specialization on a nested type?

I have a templated class Converter, and I'd like to do a partial specialization. The tricky part is I'd like to specialize it to MyFoo::Vec where MyFoo again can be specialized as a template parameter. If that sounds confusing, maybe the code itself…
Frank
  • 64,140
  • 93
  • 237
  • 324
1
vote
2 answers

C++ enum template partial specialization

I have a matrix class very tailored for the algorithm I need to implement. I know about Eigen but it doesn't fit my bill so I had to do my own. I have been working all along with Column Major ordering and now I have the strong use case to employ Row…
1
vote
3 answers

Partial template template specialization

have this code: template class OuterCont, template class InnerCont, class Alloc=std::allocator> class ContProxy { OuterCont> _container; }; typedef…
IgorStack
  • 799
  • 2
  • 6
  • 22
0
votes
1 answer

C++: Templates: Partial Specialization: Print Everything Template

Good day everybody! Having the following code: template struct print { OutStream &operator()(T const &toPrint, OutStream &outStream = std::cout) const { outStream << toPrint; …
nickolay
  • 3,643
  • 3
  • 32
  • 40
0
votes
0 answers

Template syntax for C++

I have encountered a template syntax that I am not able to understand : template struct is_same { static const bool value = false; }; template struct is_same { static const bool value =…
user2679476
  • 365
  • 3
  • 12
0
votes
1 answer

Template argument deduction with alias template partially specializing a class template

With C++20, is there a way to use class template argument deduction with an alias template that partially specializes a template class? The following code shows what I'd like to achieve but fails to compile with g++12: template
Kevlar
  • 376
  • 5
  • 15
0
votes
0 answers

Single C++ Partial Specialization for const, non-const, volatile

In the example below I can effectively strip the const, volatile and reference qualifiers and use the single specialization for shared pointers. This is solved by the adding one more level of abstraction. How could I solve this without doing so? I…
Blair Davidson
  • 901
  • 12
  • 35
0
votes
0 answers

Template member function inside template class, specialize the function

I have a template member function inside template class, this works OK, it looks like the one in the below question. Template function inside template class #include using namespace std; template class MyClass { public: …
ollydbg23
  • 1,124
  • 1
  • 12
  • 38
0
votes
0 answers

c++ Partial template specialization of function as pure vitrual

Suppose I have a template in C++ template class my_class { virtual void my_func(int i); }; Now I want to partially specialize my_func to be a pure virtual function; template<> my_class::my_func(int i) = 0; but…
Vahag Chakhoyan
  • 873
  • 1
  • 10
  • 21
0
votes
1 answer

How to define a method only when class generic type satisfies a test?

I am trying to do something like the following: class Event() { fun subscribe(handler: (payload: TPayload) -> Unit) { ... } fun subscribe(handler: () -> Unit) where TPayload : Unit { ... } } The intention is that instances of…
Sod Almighty
  • 1,768
  • 1
  • 16
  • 29
0
votes
1 answer

Function template overload with constraints

I have the following code: // converters.h #pragma once #include #include template static TTo convert(const TFrom& from) { TTo t = static_cast(from); std::cout << "From type: "…
ben yu
  • 11
  • 6
0
votes
1 answer

Template specialization with nested unspecialized type

I'm having trouble working out the syntax for a nested partial template specialization. I think that's the right way of putting it anyway. What I want is an as() function which returns a casted value. In most cases static_cast will work fine so I…
Mike E
  • 846
  • 11
  • 22
0
votes
0 answers

Why is this partial specialization not more specialized?

Why is the second version of the class not more specialized than the first? Can't the first version be further specialized with more classes than the second? Is there an obvious way to make the second class more specialized? => Switcher.hpp:122:8:…
user41010
  • 91
  • 8
0
votes
0 answers

How to partially specialize a template by STL iterator template?

I want to specialize a template by STL iterator template like: #include struct Tag0 {}; struct Tag1 {}; template struct get_tag { using tag = Tag0; }; //Wanted by failed template struct get_tag