Linked Questions

0 votes
1 answer
911 views

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

I have the following code: template<typename T> class Data { public: int size() const; private: T m_data; }; I want to implement the size() method using template specialisation methods....
Cherub's user avatar
  • 37
0 votes
0 answers
221 views

Invalid use of incomplete type for partial specialization [duplicate]

Why am I getting this error in the following: template<typename T,typename Y> class MyContainer { std::vector<T> list; public: void append( T&& elem) ; }; ...
anurag86's user avatar
  • 1,665
1 vote
0 answers
34 views

C++ partial specialization with multiple optional parameters [duplicate]

Try a partial specialization with multiple parameters. Sounds like template <class T, int E=0> class Info { public: Info& operator=(double rhs); T data; }; template<int E> Info&...
Stef's user avatar
  • 3,742
41 votes
3 answers
39k views

c++ template partial specialization member function [duplicate]

I'm new to templates so maybe this is a trivial thing but I cannot get it to work. I'm trying to get partial specialization of a class member function. The shortest code would be: template <...
Simon Righley's user avatar
12 votes
5 answers
11k views

C++ template partial specialization - specializing one member function only

Bumped into another templates problem: The problem: I want to partially specialize a container-class (foo) for the case that the objects are pointers, and i want to specialize only the delete-method. ...
Roman Pfneudl's user avatar
12 votes
6 answers
11k views

C++ partial method specialization

Is there a partial specialization for template class method? template <class A, class B> class C { void foo(); } it doesn't work to specialize it like this: template <class A> ...
faya's user avatar
  • 5,595
25 votes
4 answers
16k views

Partial specialization of a method in a templated class

Given: struct A { virtual bool what() = 0; }; template<typename T, typename Q> struct B : public A { virtual bool what(); }; I want to partially specialize what like: template<...
David's user avatar
  • 27.9k
9 votes
3 answers
5k views

Depending on a class template parameter, define or not define a function in the class

Suppose we have a class: template <class Type> class A { public: void function1(float a, Type b); void function1(float a, float b); }; Now instantiate the class like this: A<int>...
Vadim's user avatar
  • 1,243
5 votes
2 answers
6k views

Template partial specialization with multiple template argument error

When I use template partial specialization on a class with one template argument, I can specialize a method like this: #include <cstdlib> template< std::size_t Dim > class Test { public: ...
Philippe Cayouette's user avatar
0 votes
3 answers
1k views

Templated Vector and Colour Maths library (Specialisation)

I have created a maths library that operates via templates, it allows the user to specify the size and type of the array within a class which is then used to create a maths vector of any dimension up ...
Sent1nel's user avatar
  • 509
0 votes
6 answers
791 views

Template casting issue

I seem to be getting an error in the below code when I attempt to cast to a template of class T, when T is of type float. I have realized already that a type of int functions correctly, because the ...
Jamie's user avatar
  • 2,245
2 votes
1 answer
940 views

Specialize member function of class template using C++20 concepts

I want to specialize a member function of a class template as follows: #include <concepts> template <typename T> struct S { void f(); }; template <typename T> void S<T>::...
fdev's user avatar
  • 147
2 votes
1 answer
936 views

partial specialization of function in template class

I have a template class representing an array of numerical values. I want this class to work for any type of numerical value (e.g. int, double, etc.) and three types of container (std::vector, std::...
kokozul's user avatar
  • 41
-1 votes
2 answers
254 views

How do I initialize a non-static member variable in a struct template?

I have an existing struct as follows: template<typename T> struct Foo { T bar; Foo() {} Foo(T bar) : bar(bar) {} }; How do I provide a specialization so that T bar is set to a ...
Class Skeleton's user avatar
1 vote
2 answers
182 views

C++ partial template specialization

Is this answer considered "good" code or is it just an ugly hack? And I would like to know how this is forward-declared (both classes). When I just forward-declare the class with 2 template-...
Atmocreations's user avatar