explicit-specialization Questions
1
Solved
Consider the following code:
#include<concepts>
template<typename>
void foo() { }
template<std::integral>
void foo() { }
template<>
void foo<bool>() { }
int main...
Tirado asked 9/10, 2023 at 18:38
2
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 t...
Stammel asked 22/12, 2021 at 11:32
3
I'm working on a codebase which uses the following structure:
a.h:
template<int N> void f();
void b();
a.cpp:
#include "a.h"
template<> void f<1>() {}
int main()
{
b...
Interpose asked 11/4, 2020 at 1:10
1
The following code compiles fine with clang++ 6.0.0 and g++ 7.3.0 (compilation flags are -std=c++14 -Wall -Wextra -Werror -pedantic-errors) but fails to compile with vc++ 19.10.25017 (compilation f...
Lowney asked 23/4, 2018 at 15:38
5
Solved
I'm on a roll today. Here goes n00b question number 7:
What's the difference between explicit specialization and just regular functions when you try to overload a template function?
What's the ap...
Sopor asked 13/5, 2011 at 3:20
1
Solved
Considering this code:
template <class T>
void f(T p) { //(1)
cout << "Second" << endl;
}
template <>
void f(int *p) { //(2)
cout << "Third" << endl;
}
tem...
Imena asked 19/6, 2017 at 7:10
1
Solved
I have a class with a member template function:
// writer.h
class Writer {
public:
...
template <typename T, typename V>
void addField(const std::string& name, V v)
{
// write some...
Delibes asked 29/5, 2015 at 13:2
1
The code
template <typename T>
void foo(const T& t)
{}
template <typename T>
class A
{
template <>
friend void foo<T>(const T& t)
{}
};
gives compile error
...
Sisk asked 4/1, 2015 at 15:35
1
Solved
Previous question.
I repeat the code from the previous question to make this question self-contained. The code below compiles and does not issue any warnings if it is compiled using gcc 4.8.3. wit...
Otho asked 24/12, 2014 at 0:6
1
Solved
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 ...
Erythrism asked 23/12, 2014 at 22:35
1
Solved
I'm wondering why the following code runs just fine in gcc
#include <iostream>
using namespace std;
template<typename T>
struct F {
static T const value;
};
template<>
struc...
Thibeault asked 20/6, 2014 at 18:40
1
Solved
I had the (seemingly) bright idea of using extern template class std::shared_ptr<SomeWidelyUsedClass> in stdafx.h immediately after #include <memory> in order to prevent std::shared_ptr...
Jacquiline asked 1/5, 2014 at 16:3
1
As a follow-up to my previous question, I am trying to detect the existence of a template function that requires explicit specialization.
My current working code detects non-template functions (th...
Amethyst asked 21/9, 2013 at 18:45
2
Solved
The One Definition Rule states that a program should contain one definition of every non-inline function. For members of template classes, this not entirely clear to me:
///////////
// Tfoo.h
t...
Cassady asked 23/4, 2013 at 8:25
1
Solved
I got an error in the code below:
template<typename T, bool B = is_fundamental<T>::value>
class class_name;
template<>
class class_name<string, false>{
public:
static str...
Glacialist asked 6/1, 2013 at 1:41
1
Solved
As an example, suppose I want to write a monadic and non-monadic map over lists. I'll start with the monadic one:
import Control.Monad
import Control.Monad.Identity
mapM' :: (Monad m) => (a -&...
Pathan asked 20/10, 2012 at 20:42
2
Solved
I have a template method as follows:-
template<typename T, int length>
void ProcessArray(T array[length]) { ... }
And then I have code using the above method:-
int numbers[10] = { ... };
...
Unworldly asked 24/6, 2012 at 17:8
2
Solved
I'm writing a class that has an unordered_set of its own type as a member.
Therefore I need to write a specialization for hash<Foo>. This specialization needs to be defined after Foo is decla...
Barrack asked 8/1, 2012 at 22:22
1
Solved
Users are allowed to add explicit specializations to the std namespace. However, there are a few templates that I am explicitly forbidden from specializing.
What templates can and can't I speciali...
Somerville asked 14/12, 2011 at 23:54
2
Solved
It would be nice if this code were invalid. But it's conceptually sound, and GCC accepts it although Comeau doesn't:
template< typename > struct t;
template<> struct t< int > {}...
Ypsilanti asked 10/6, 2011 at 9:9
3
(Note: I know how it is illegal, I'm looking for the reason that the language make it so.)
template<class c> void Foo(); // Note: no generic version, here or anywhere.
int main(){
Foo<i...
Oakleil asked 3/5, 2011 at 17:33
6
Solved
Is following design possible?:
template <typename T>
class Test{
public:
template <typename Z>
void doSomething();
//rest of things
private:
T obj;
//some things
};
Now if it ...
Neume asked 25/11, 2010 at 8:1
2
Solved
After asking this question and reading up a lot on templates, I am wondering whether the following setup for a class template makes sense.
I have a class template called ResourceManager that will ...
Unload asked 20/8, 2010 at 19:44
6
Solved
Hi I'm having problems selecting the correct version of a templated class which has an explicit specialization. I'm wanting to select a specialization using a derived class of the class used to spe...
Enterovirus asked 22/1, 2010 at 16:38
2
Solved
I have a template class that looks something like this:
template<class T> class C
{
void A();
void B();
// Other stuff
};
template<class T> void C<T>::A() { /* something */ ...
Assimilative asked 26/9, 2009 at 17:20
1 Next >
© 2022 - 2024 — McMap. All rights reserved.