1,685 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
1
answer
120
views
Does an explicit instantiation declaration allow an explicit template specialization to be only declared in a separate translation unit?
Short version: Does an explicit instantiation declaration guarantee that a visible template definition is never used (unless an explicit instantiation definition is also encountered), and therefore ...
2
votes
1
answer
103
views
Is it possible to distinguish an instantiation of a primary template from instantiation of a (partial) specialization?
Given a template T and some type U, I can write a trait to see if U is an instantiation of T. For a simple case of a single template argument the trait could look like this:
#include <type_traits&...
2
votes
3
answers
284
views
Why is a custom specialization of std::hash<std::string> allowed?
I implemented std::hash<std::string> in the usual way, by specializing the std::hash template. But then I realized that these should already be provided by the <string> header (https://www....
1
vote
1
answer
108
views
Detecting if a function template specialization exists and returning a function pointer to a valid implementation
I have a project where I use function templates to allow users to swap in function specializations at compile time, so there is a default version provided in a library of common code and an optional ...
0
votes
0
answers
58
views
How to specialize a template method for char[]? [duplicate]
I'm attempting to create a catch-all template method of Foo::show and specialize a few types. In the example below, the specialization of double and char* when "asdf" is passed. But when I ...
3
votes
1
answer
124
views
template class method specialization compilation error
I'm making my own test framework in c++ in order to learn more of this language (and wow how much I learned), but I've just hit a critical point -> I try to specialize my contains check to fail ...
0
votes
1
answer
166
views
Template factorial function improvement
I started learning patterns in c++ and tried to create a factorial function that, if possible, will be executed in compile time.
Tell me how I can improve my implementation.
Concept to check if T is ...
8
votes
1
answer
415
views
How does auto return type template specialization work with different return types?
I'm reading "C++17 The Complete Guide" by Josuttis, and he mentions off-hand in an early chapter that full template specializations must have the same signature and return type because ...
1
vote
2
answers
100
views
Templated specialization of method in templated class
I have a templated class Widget, which can store either primitive types, or types of another templated class Foo. I would like to access value stored in Widget directly for primitive types, or by ...
2
votes
2
answers
109
views
std::enable_if for partial specialization
I am implementing a template Matrix class (depending on the underlying datatype and the size) and want to specialize some methods (determinant, inverse) for some specific sizes (2, 3 and 4).
I first ...
0
votes
1
answer
80
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 (...
3
votes
3
answers
127
views
Determine the parameter types of a function passed as a template parameter
Given a function passed as a template argument to a function, how can I determine the type of the of it's first parameter?
For example:
template<auto Func>
void run_func(/* type of argument???? *...
0
votes
1
answer
51
views
How does template specialization work for hierarchies of template classes?
Below I have two separate templated class hierarchies (Account -> CheckingAccount and Logger -> ConsoleLogger) and a template Bank class that uses both.
The goal is to use different Loggers, one ...
2
votes
1
answer
63
views
C++: Template specialization of class member function, differing from another member function only in accepting parameters by reference, not by value
Within template class Bank<T>, my goal is to create an overload for type Account to member function void Bank<T>::makeTransfer(T, T, const double), of signature void Bank<Account>::...
3
votes
1
answer
97
views
Is explicit specialization of a class template via a using alias supposed to work?
Fist of all, what I'm doing seems to work on all of GCC/Clang/MSVC/icc/etc, so my question is; is that by accident or does the standard require it to be allowed?
In one way it seems like a logical ...