Template argument deduction is a compiler attempt to deduce template arguments when some are omitted.
Questions tagged [template-argument-deduction]
692 questions
0
votes
1 answer
Template deduction with another template parameter that has a default value
The code below will not compile, because when I want to specify Param, type deduction of A and B is disabled and I would have to specify those explicitly as well.
#include
template
struct L
{
};
template

Post Self
- 1,471
- 2
- 14
- 34
0
votes
1 answer
How the first argument in template parameters list getting skipped form call parameters?
I was experimenting to find how arguments are deduced when we use templates in c++, I came though a case which was strange for me.
As per my understanding template parameters should be present in call parameters.
But in the code below, I tried to…

Vikram Singh
- 273
- 1
- 3
- 10
0
votes
1 answer
Scenarios where template deduction requires user-defined implicit conversion
I have a class template that includes an overloaded operator template and an implicit conversion constructor, similar to the following:
#include
template
class X {
public:
A a;
B b;
X(A a, B b) : a(a), b(b)…

Nick Mertin
- 1,149
- 12
- 27
0
votes
0 answers
c++ static array wrapper
I'm trying to build a wrapper class for static array, which should behave like a standard static array.
int main()
{
int t[2][3] = {{77, 2, 3}, {4, 5, 6}};
auto a = make_array(t);
auto b = a[0]; // gives a ArrayWrapper
auto c = b[0];…

Dorian
- 490
- 2
- 10
0
votes
2 answers
compile error about template deduction on c++
#include
template
class X {
public:
using I = int;
void f(I i) {
std::cout…

Daniel Lee
- 205
- 3
- 7
0
votes
0 answers
Pass a templated class instance to another class' constructor
I am looking for a way to pass an instance of a templated class to another class.
The context:
I am working with a library (that I don't want to edit for now) containing a templated class of this style:
//my templated class
template…

LeSinge
- 1
0
votes
1 answer
Can't deduce template parameter when helper template struct is used
I would like to make some template functions work with existing template-struct helpers. However template argument deduction fails. Is there a work-around?
Example
This overloaded operator << compiles and works:
template
inline typename…

AMA
- 4,114
- 18
- 32
0
votes
1 answer
Can I specify comparator using std::set constructor without specifying all the template arguments
I want to construct a set with lambda comparator.
Due to known limitations you can not specify lambda as template parameter(you need to decltype() it) so I thought about specifying the key of the map in the template argument list and comparator in…

NoSenseEtAl
- 28,205
- 28
- 128
- 277
0
votes
1 answer
passing overloaded function pointer as argument to overloaded template function
I'm trying to get the compiler to deduce the correct function template.
Given the following code, the correct templated function is deduced...
class TestBase{};
template
inline void CallF( RT( c::*M )(T0),…

Danny Diaz
- 230
- 2
- 10
0
votes
1 answer
C++17 class template argument deduction guides and string literals
The constructor takes T by value, so string literals will decay to char const*.
With the deduction guide Stack(char const*) -> Stack,
I expect both cases to work.
Why the second argument deduction Stack ss2 = "string literal" does…

Amin Roosta
- 1,080
- 1
- 11
- 26
0
votes
2 answers
Template type deduction in function return type
This is in continuation with the question posted at Template type deduction for member variables and function arguments
My .h file contains the following lines.
#include
#include
#include
template
class…

Soo
- 885
- 7
- 26
0
votes
1 answer
Template type derivation
I need to implement a class, say 'MyClass' using templates.
template
class MyClass
{
public:
T var1;
T1 var2;
};
There are two member variables var1 and var2. If the class template argument, 'T', is…

Soo
- 885
- 7
- 26
0
votes
1 answer
finding the type of a templated derived class
I have a vector container holding pointers of a base class:
class Wrapper_base {
public:
virtual ~Wrapper_base() {}
};
template
class Wrapper : public Wrapper_base {
private:
T t_;
public:
Wrapper(const T t) : t_(t)…

Arash
- 141
- 10
0
votes
2 answers
Automatic template type deduction confusing pointers and references
Whilst trying to debug some code, I created a class to dump the values of a complicated hierarchy of objects to a text file so that I can compare a case where it works against a case where it doesn't. I implemented the class like this (reduced to a…

Charles Blessing
- 23
- 5
0
votes
1 answer
SFINAE and template function instantiation: Why a template argument cannot be deduced when used in function arguments with a SFINAE-enabled type?
I was experimenting with SFINAE these days, and something puzzles me. Why my_type_a cannot be deduced in my_function's instantiation?
class my_type_a {};
template
class my_common_type {
public:
constexpr static const bool valid =…

Flávio Lisbôa
- 651
- 5
- 19