Why doesn't the Lambda Function auto visitor = make_forwarding_visitor<std::string>([](const auto& t){ return t.name();});
have two arguments given that the struct forwarding_visitor has two parameters?
It does have two arguments. The first one is std::string, and the second one is chosen by the compiler following a process called "function template argument deduction".
I have no trouble getting the function in the struct to print but I cannot use std::is_same to show that the type is Person or Dir?
This is because Arg is Person& and Dir&, explaining why you need decay_t
It does have two arguments. The first one is std::string, and the second one is chosen by the compiler following a process called "function template argument deduction".
Where exactly is it in the code where the compiler deduces the second parameter or where is the second parameter declared initially?
Is it this, constauto& t inside the Lambda declaration?
Just want to make sure I understand it.
Is this line a function pointer?
make_forwarding_visitor<std::string>(...);
because Lambdas usually start with square brackets []...
The second template argument to make_forwarding_visitor is deduced from the first (and only) function argument.
auto visitor = make_forwarding_visitor<std::string, ...>([](const auto& t){ return t.name();});
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| The compiler sees |
| the type of the |
| lambda expression |
| and uses it to |
| deduce the |
| template argument. |
|____________________|