With class template argument deduction we can write:However, G++ 8.2 rejects this code:emitting the following error:
Could you help me understand why the argument deduction works for the class template and does not work for the function template?
In the code below, why do the two ways of invoking fun: fun(num) and fun<const int>(num), give a different result when compiling?
In the code beside , why the 2 ways has different result when compile, between fun(num) and fun<const int>(42)?
The most obvious answer could be - because the standard says so. That's fine, but I'm wrapping my head around it to understand the reasons behind this choice.
This question already has an answer here:One of the places I hoped I would be able to use the new template argument deduction, was in construction of std::set's / std::maps / any other containers with custom comparators - my goal is to create a one-line statement, that will create an...
As I understand,T for #1 will be deduced using the implicit deduction guide generated from the first ctor. Then x will be initialized using that ctor.