Questions tagged [explicit-specialization]
71 questions
3
votes
1 answer
Declaration doesn't solve 'explicit specialization after instantiation' error
Suppose I am attempting to create my own implementation of boost::filesystem::path, using the Curiously Recurring Template Pattern:
(Code is given incomplete for brevity, but will exhibit the problem as stated when compiled with 'g++ -std=c++11 -o…

Cognitive Hazard
- 1,072
- 10
- 25
3
votes
1 answer
explicit specialization for function template c++
template
bool validate(const T& minimum, const T& maximum, const T& testValue) {
return testValue >= minimum && testValue <= maximum;
}
template <>
bool validate(
const char& minimum,
const char& maximum,
…

Andy
- 127
- 2
- 9
3
votes
1 answer
Explicitly specialized members need their containing class templates to be explicitly specialized as well
I read in many articles, that for class template when specializing
member template, the class that containing specialized member template also shall be explicitly specialized. Is there a point about it in standard and is there any reason to have…

Vahagn Babajanyan
- 379
- 2
- 12
3
votes
2 answers
"expected initializer before '<' token" attempting template member specialization
I'm trying to define a template member inside a template class.
Here is a fragment of the header file:
template
class Queue
{
private:
// class scope definitions
// Node is a nested structure definition local to this class
…

Kurospidey
- 393
- 1
- 4
- 18
2
votes
2 answers
what is the type of decltype(function) and why I do not need "const" qualifier here?
I am confused of the type of decltype a function. It is neither a function pointer nor functor. How can I use it? And why the full template specialization here does not require const qualifier.
class SomeClass
{
public:
template
…

Wubin Ouyang
- 777
- 1
- 7
- 9
2
votes
1 answer
explicit specialization of a function template (which is a member of a class template) produces "partial specialization is not allowed" error, why?
I am working on Visual Studio 2015 community edition
let's say I have, a simple class like this:
(The example below "should be" a compilable because it include all the necessary stuff, unfortunately, it produces an error).
#include…

PatrykB
- 1,579
- 1
- 15
- 24
2
votes
1 answer
swift: How to write generic function that calls specialized ones
The best way to describe what I want is by this example:
protocol Lerpable {
// here should be 'lerp(_ x: CGFloat, _ a: T, _ b: T) -> T' function
}
extension CGFloat: Lerpable {}
extension CGPoint: Lerpable {}
extension CGRect:…

brigadir
- 6,874
- 6
- 46
- 81
2
votes
1 answer
template-template-parameter deducation failed for template method (although explicitly-specialized)
I am attempting to write a small script interpreter that is extensible via c++. For that purpose function handlers are inserted into a dispatch table.
To simplyfy my question, the handlertype is defined as follows (in the real code, this contains…

Sebastian Büttner
- 351
- 3
- 13
2
votes
3 answers
Function Templates - Explicit specialisation vs Global Functions (C++)
I know that Function Templates are used so as to make the functions portable and so that they could be used with any data types.
Also Explicit Specialization of templates is done if we have a more efficient implementation for a specific data…

Pavitar
- 4,282
- 10
- 50
- 82
2
votes
2 answers
Why is explicit specialization of a member not allowed without specializing the class?
The C++ standard states the following:
In an explicit specialization declaration for a member of a class template or a member template that
appears in namespace scope, the member template and some of its enclosing class templates may remain
…
user3725343
2
votes
1 answer
Normal function not overwriting template function
I have to use an external library, but am getting a "multiple definition error" from following template function and its explicit specialization, if it gets called with a std::string.
template
void foo(T& value);
template <>
void…

randooom
- 541
- 2
- 11
2
votes
3 answers
How to specialize member functions based on class template argument
What the question says. In addition, is it possible to do this inline?
Here is a small example just to give an idea...
template
class Foo {
public:
Foo() :z(0.0) {}
void do( const Foo &f ) {
z = f.z;
}
// specialize 'do'…

floogads
- 271
- 2
- 4
- 13
2
votes
2 answers
Way to set up class template with explicit instantiations
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 only be loading a few specific resources like…

rhubarb
- 417
- 1
- 4
- 7
2
votes
1 answer
Specify context from where comes term in Haskell
Here is a dummy example:
class Test a b where
witness :: a
f :: Test a b => a
f = witness
Haskell then say
Could not deduce (Test a b0) arising from a use of ‘witness’
from the context (Test a b)
bound by the type signature for f :: Test a b…

abitbol
- 487
- 4
- 8
2
votes
1 answer
extending namespace std via partial template specialization
As far as I know, we are allowed (with some exceptions that I won't mention here) to "extend" namespace std by totally specializing a std template function such as std::swap, i.e.
namespace std
{
template<>
void swap(Foo& lhs, Foo&…

vsoftco
- 55,410
- 12
- 139
- 252