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
0
votes
0 answers
std::reference_wrapper in a class template argument deduction guide?
This verges on code review/best practices, but… is it reasonable to do this?
// A metafunction to map T -> T but std::reference_wrapper -> T&:
template struct RefWrapperToRef { using type = T; };
template struct…

Ben
- 9,184
- 1
- 43
- 56
0
votes
0 answers
How to add a user-specified compile-time integer constant to a variadic class template?
I'm trying to write a certain class with the following functionality.
Outside, I have a collection of classes which define a type and a member function:
class X
{
public:
using energy_t = std::array; // N is some number 1,2,3...
…

Bbllaaddee
- 145
- 1
- 9
0
votes
0 answers
CTAD and template constructor with member with parameter pack
Trying to use universal references with CTAD and parameter pack I tried something like below, but it doesn't compile on MinGW GCC. And I don't understand why.
This is the sample code:
#include
template
struct Subtest
{
…

Andrei
- 360
- 2
- 9
0
votes
0 answers
Why CTAD failed for std::unique_ptr(new int()) in C++17?
Why C++17 class template argument deduction failed for
std::unique_ptr(new int());
What could the compiler imagine it to be rather than std::unique_ptr?

Ioann
- 1
- 1
0
votes
0 answers
CTAD recursion problem for function wrappers with wrapper pointer as function argument
I have a templated function wrapper with template type equal to return type of the function. Further the function's first argument is a pointer to the wrapper itself.
template
struct wrapper_t{
using result_t = R;
…

ezegoing
- 526
- 1
- 4
- 18
0
votes
1 answer
How to define deduction guide with templated constructor?
In order to simplify my problem, I'll be using std::unique_lock as the tool to explain.
std::unique_lock has a template argument, the mutex. However, it's constructor is also a template function unique_lock(TMutex &, const chrono::duration<_Rep,…

JVApen
- 11,008
- 5
- 31
- 67