Class Template Argument Deduction, introduced in C++17, allows deducing missing template arguments for class template instantiation based on the initializer.
Questions tagged [ctad]
66 questions
1
vote
1 answer
function object argument deduction with c++17 CTAD
I have a lot types to use compare functors, and I would like to see if there is way to simplify it without passing the argument. Here is a dummy code example:
struct Base{};
template struct Compare {
bool operator()(const T& a, const…

pepero
- 7,095
- 7
- 41
- 72
1
vote
0 answers
CTAD(?) on function parameter of function template
Why does this code not work:
template
struct ts
{
inline ts( valueType v )
{}
};
template
inline void test( ts str )
{}
void testfun( void )
{
test( 1 ); // ERROR: ts

rplgn
- 111
- 7
1
vote
0 answers
CTAD for templated function
I am writing a logging class, which uses source location as a defaulted argument.
I'd like to have a printf-like function call which I hope should be possible using CTAD, but in this case it is for a templated function rather than a templated class,…

GreenaGiant
- 73
- 9
1
vote
1 answer
C++ provide only undeducable template types
Assume we have class that depends on two template types one of we specialize in constructor, can we not specialize deducable type?
template
class A {
public:
A(I i) {
}
};
int main() {
A a(42); //…

Vladyslav Mozhvylo
- 331
- 1
- 2
- 11
1
vote
2 answers
How to use CTAD for a lambda?
Good afternoon, everyone. I implemented a couple of classes:
// CallingDelegate
template
class CallingDelegate
{
using TypeDelegate = std::function;
public:
CallingDelegate() = delete;
…

Олег Привалов
- 171
- 2
- 14
1
vote
1 answer
std::invoke substitution failure for member function pointer
I'm working with webview (found here: https://github.com/webview/webview) to create a c++ program with a html/js gui. In order to call c++ functions from js, they must be in the form std::string function(std::string). This is fairly trivial for free…

Naitsirk
- 13
- 3
0
votes
1 answer
Template argument deduction with alias template partially specializing a class template
With C++20, is there a way to use class template argument deduction with an alias template that partially specializes a template class?
The following code shows what I'd like to achieve but fails to compile with g++12:
template

Kevlar
- 376
- 5
- 15
0
votes
0 answers
Something like CTAD for implicit conversions without inheritance?
I'm using C++20.
template struct Foo {};
template struct Bar {
constexpr operator Foo() const { return {}; }
};
template void foo(Foo) {}
void bar(Foo) {}
int main() {
Bar b;
bar(b); //…

Chris Elrod
- 357
- 2
- 8
0
votes
2 answers
Deduce types of template-defined base class constructor parameters
I have a derived class, Wrapper, that inherits from a template-defined base class. I'd like to configure Wrapper so that if the base class has constructor parameters, Wrapper's constructor also includes the base class's constructor params so that it…

Conor Taylor
- 2,998
- 7
- 37
- 69
0
votes
0 answers
CTAD for class members in member initializer list?
I wanted to see if I can deduce the template parameters of a member class object in the member initializer list. I suppose this is not (yet) possible. Am I right in assuming so?
Demo
#include
template
struct…

glades
- 3,778
- 1
- 12
- 34
0
votes
0 answers
Omit template parameter for return type
I might have a leak of memory (literally, not in code), I just cannot recall what this feature of C++ is called that allows you to omit the template parameter types in the following scenario:
#include
#include
std::vector…

Ferenc Deak
- 34,348
- 17
- 99
- 167
0
votes
3 answers
Class template argument deduction using function return type
I want to make a class with a template parameter and a function (also with a template parameter) that returns a class instance.
However, for shorter code, I want to omit template parameters when returning the result of class construction.
I have no…

Garden
- 36
- 5
0
votes
0 answers
Deduce one of two template parameters with parameter pack in C++20
I have an N-dimensional array class with two template parameters, a class and a size_t. To construct a 3-dimensional array of size x by y by z, I would like to be able to use:
ArrayND A(x, y, z);
...but can't figure out how to do so--as it…

Michael Greenburg
- 141
- 1
- 6
0
votes
1 answer
CTAD doesn't work with defaulted template arguments?
Compare the following case when I have a class object that takes a vector. The non-deduced parameter T can be substituted fine with the default template argument:
#include
template
struct container
{
…

glades
- 3,778
- 1
- 12
- 34
0
votes
1 answer
Partial deduction of template parameter using constructor
I have seen this asked before in several ways, and all the solutions are always the same: use a helper function or even use nested classes. For me, both of those solutions look clumpsy. So I wonder how come in the c++17/c++20 era there is not better…

Pablo
- 557
- 3
- 16