Template argument deduction is a compiler attempt to deduce template arguments when some are omitted.
Questions tagged [template-argument-deduction]
692 questions
0
votes
3 answers
Automating a class template's size argument based on its type argument
While working with class templates, is there a way to specify a particular size by inferring from its type? Here is a pseudo code example to represent what I'm trying to ask.
#include
#include
namespace xxx {
#define BYTE …

Francis Cugler
- 7,788
- 2
- 28
- 59
0
votes
1 answer
deduction guide breaks for templated derived class
Here is minimal example:
#include
struct base_pod
{
};
template
struct der_pod : public base_pod
{
T k[N];
};
template
der_pod(T, U...)
…

Chen Li
- 4,824
- 3
- 28
- 55
0
votes
2 answers
Function template argument deduction and inheritance
I thought that the function overload with the most specific matching argument types would be called, but it seems I don't understand an aspect of type deduction when template and inherited types are combined.…

Greg von Winckel
- 2,261
- 2
- 16
- 14
0
votes
2 answers
Pass a template variadic function and its arguments to a function
I would like to be able to pass a function taking any number of arguments, plus the matching arguments, as arguments to a function. This is what I've tried so far, I'm lost as I don't quite get a grasp at how parameter-packs work.
template

Torayl
- 57
- 6
0
votes
3 answers
Initialise `std::array` with parameter pack arguments
There's structure HasArray with template parameters typename T and size_t N.
template
struct HasArray {
// enable_if sizeof...(T) equals N
template

Tom
- 3,281
- 26
- 33
0
votes
2 answers
Template argument deduction / variable template: how can I make it work?
I have a problem in wrapping a template class in a non-template one;
I'm trying to make this code work:
my_class.hpp
#ifndef MY_CLASS_HPP
#define MY_CLASS_HPP
#include
#include
class VectorPrinter {
private:
template

Michele Pellegrino
- 11
- 4
0
votes
2 answers
Get return type of lambda expression
I am developing a C++ iterator that evaluates a lambda expression each time the iterator is dereferenced.
So I implemented a custom iterator class, and I overloaded the dereference operator, in a way it executes the lambda expression on each…

Alex
- 886
- 1
- 9
- 18
0
votes
1 answer
c++ template argument match std::function with function pointer
I have a function wrapper that takes a function and a list of arguments and calls the function with those arguments:
template
R wrapper(std::function f, Args... args) {
auto ret = f(args...);
return…

zeralight
- 620
- 1
- 5
- 19
0
votes
1 answer
Use of auto in template parameters: Some usage examples and... how to make it work with constant size C arrays?
I have the following exemplary use of auto in template parameters (which I like independent of their sanity or existence of better alternatives, I am just trying to internalize the 'auto in template params' feature):
//1-Check if input is within…

mami
- 109
- 1
- 7
0
votes
1 answer
How to pass a template lambda to a function and use it with different types
I have this code inherited from old C++ time using macros. I'm currently replacing it, and I'm at the point where some constructs need to be factored.
Typically, I have this:
if(condition)
{
fun1(fun2(arguments, arg1)); // let's say arg1 is a…

Matthieu Brucher
- 21,634
- 7
- 38
- 62
0
votes
1 answer
C++: Extracting parameter type from static function in struct
Say I have something like this:
template
struct MyStruct {
static R myfunc(T);
};
struct MyStructInst: S {
static double myfunc(int i) { return i; }
};
Then later, I have a template that takes M, a type…

Sebastian
- 715
- 6
- 13
0
votes
1 answer
template type deduction even with empty list
I was reading on cppreference that :
Class template argument deduction is only performed if no template
argument list is present. If a template argument list is specified,
deduction does not take place.
with followed examples :
std::tuple…

Blood-HaZaRd
- 2,049
- 2
- 20
- 43
0
votes
1 answer
Express constraints when using C++ templates
I have a Wrapper class. Any T or objects derived from T should be convertible to this Wrapper.
I would also like any object of 'Someclass' or objects derived from 'SomeClass' to be convertible to Wrapper. The implementation in both cases needs to…

Arun
- 3,138
- 4
- 30
- 41
0
votes
1 answer
Default template argument deduction for copy initialization
C++17 has class template argument deduction. However, I was wondering whether it applies to statements like auto x = X() where X is a class template. Consider this code:
template
struct X {};
int main() { // all with…

jcai
- 3,448
- 3
- 21
- 36
0
votes
0 answers
Variadic function templates, argument order, and deduction
I'm trying to write a variadic template function which will construct a linear combination of Eigen matrices, taking advantage of the expression support. (Hence why I want to use a variadic template rather than a simple loop.)
However, I'm having a…

kc9jud
- 146
- 1
- 11