78 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
13
votes
1
answer
236
views
Redefinition of deleted function of implicitly instantiated class
Consider the following example from [temp.inst.3]:
template<class T>
struct C {
void f() { T x; }
void g() = delete;
};
C<void> c; // OK, definition of C<void&...
0
votes
1
answer
81
views
Template template partial specialization
Consider the following class template.
template<template<typename U> typename T>
class Entity {
// Something
};
What is the proper syntax to specialize Entity explicitly:
by U,
by T (...
1
vote
1
answer
142
views
Resolving compilation error with template specialization
I am having issues in understanding and fixing a compiler error that I see with MinGW (UCRT64) C++20, but that I don't see when I build the code with MSBuild C++11.
header.h: (Only relevant code)
#...
3
votes
1
answer
154
views
Are we allowed to explicitly specialize inline static data member of a class template without specializing the class template itself
I wrote the following snippet that compiles with clang but gcc and msvc rejects it. Demo
#include <iostream>
#include <iomanip>
//wrapper
template<typename T>
struct Wrapper
{
...
0
votes
1
answer
48
views
Explicitly specialize templated constructor with zero arguments [duplicate]
Suppose the following class:
class JsonDocument
{
public:
using RootType = size_t;
constexpr static RootType ObjectRoot = 1;
constexpr static RootType ArrayRoot = 2;
template<
...
6
votes
1
answer
239
views
Ambiguous template specialization with concepts and real types: which compiler is right?
Consider the following code:
#include<concepts>
template<typename>
void foo() { }
template<std::integral>
void foo() { }
template<>
void foo<bool>() { }
int main() {...
4
votes
1
answer
178
views
Inheritance and conditionally explicit constructors
The use case is for a subclass of std::expected, but the following reproduces the behaviour I'm interested in.
#include <type_traits>
template<class T>
struct Foo{
T value;
constexpr ...
0
votes
1
answer
243
views
How to differentiate between the different types of C++ specializations when writing/speaking
I think some of my confusion over what "Specialization" means is that it appears to have two related, though distinct meanings. These are the two definitions I've seem to come across:
From ...
0
votes
2
answers
84
views
error in template function when i even didn't use it
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
template<class T>
T maxn(T* a,int n);
template<> void maxn(const char* s[],int n);
int ...
0
votes
3
answers
99
views
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<...
0
votes
0
answers
36
views
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::...
18
votes
2
answers
368
views
Is there provision specifying the restriction on "return type" in a function template explicit specialization?
template<class T>
void fun(T){}
template<>
int fun(int){return 0;}
Consider this example, it is rejected by all implementations. However, I haven't found any persuasive provision in the ...
0
votes
1
answer
309
views
How to explicitly instantiate a func template with no parameter?
I have a member func template as following:
using ArgValue_t = std::variant<bool, double, int, std::string>;
struct Argument_t {
enum Type_e { Bool, Double, Int, String, VALUES_COUNT };
...
1
vote
1
answer
905
views
C++: specializing member requires template<> syntax
I am trying the following...
#include <iostream>
using namespace std;
template<class T>
class Singleton
{
private:
class InstPtr
{
public:
InstPtr() : m_ptr(0) {}
...
1
vote
1
answer
295
views
OpenGL -- Explicit specialization in non-namespace scope -- Function templates [duplicate]
Recently I was learning OpenGL basics from YouTube and while I was working with VS C++ compiler, everything worked like a charm, but since I moved to Clang I get error "explicit specialization in ...