Questions tagged [explicit-specialization]
71 questions
0
votes
2 answers
error in template function when i even didn't use it
#include
#include
#include
using namespace std;
template
T maxn(T* a,int n);
template<> void maxn(const char* s[],int n);
int main()
{
// int n6[6]{21,56,89,49,258,41};
// double…
0
votes
3 answers
What is the need for having two different syntaxes for specializing data member of a class template
I was writing an example involving specialization of class template where I noticed that the standard allows two different syntax for specialization of a data member as shown below:
template
struct C {
static int x;
};
template<>…

Jason
- 36,170
- 5
- 26
- 60
0
votes
0 answers
Add function template specialisation for double types only in a template class
I have an implementation of a class template with a base class.
class MyBase
{
protected:
virtual void getErrorPercent(std::ostream& fileStream) = 0;
virtual void getFormattedText(std::ostream& fileStream) = 0;
};
template
class…

Diz
- 1
0
votes
1 answer
How to explicitly instantiate a func template with no parameter?
I have a member func template as following:
using ArgValue_t = std::variant;
struct Argument_t {
enum Type_e { Bool, Double, Int, String, VALUES_COUNT };
template
as( const Argument_t& def )…

Leon
- 1,489
- 1
- 12
- 31
0
votes
0 answers
Explicit specialization in define causes error: explicit specialization in non-namespace scope
I'm getting explicit specialization in non-namespace scopeerror from this define:
#define DECLARE_INTERNAL_LINK_SPECIALIZATION(T, Counter) template<> struct T
This is how the define is used, which triggers the error:
#define…

ZeroPhase
- 649
- 4
- 21
0
votes
0 answers
Specializtion of function template with non-type template parameters
I used function template to calculate the determinant of a n dimension matrix.
template
double get_cofactor(double A[dimension][dimension],
double temp[dimension-1][dimension-1],
int p, int…

herbertluo
- 59
- 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…

soulmachine
- 3,917
- 4
- 46
- 56
0
votes
1 answer
C++ explicit return type template specialisation
This is a follow up on this (more general) question: previous question. A partial answer to the present question is given here: partial answer to the present question.
I am interested in explicit specialisation of the return type based on the…
user1391279
0
votes
2 answers
Why can't I call the C++ explicit specialization version of following code?
Introduction:I want the explicit sepiaclization to show the longest string, I thought it be "Carmelo Anthony", but the result is "Jordan". I know the general template version is used instead of the explicit one. So it just compare the point's…

Marvin Dev
- 73
- 1
- 1
- 7
0
votes
2 answers
Nested Template Specialization
I have a templated class that needs a specialized constructor when the template parameters is the same type as the class. The code below won't compile.
What's the correct syntax for specifying the use of a particular constructor when the type is…

Ben Jones
- 919
- 1
- 8
- 22
0
votes
1 answer
How do I fully specialize a function template with a class template?
template
void foo(T t)
{
... // do stuff with type T
}
template
class class_template
{
// class body
};
template<> // failed attempt at full specialization
void foo(class_template t) //…

hawk
- 1,827
- 2
- 14
- 28