Question:
Parameterized type problem.. WT.. [c++]?
gh0st Rider
2011-11-19 10:02:46 UTC
template
T const& max (T const& a, T const& b)
{
return a}

int g = max(1, 1.0);

I am trying to find meaning of this Holy sentence "The deduction process compares the types of an argument of a function call with the corresponding parameterized type of a function template and attempts to conclude the correct substitution for one or more of the *deduced parameters*. Each argument-parameter pair is analyzed independently, and if the conclusions differ in the end, the deduction process fails"

Can anyone please please please explain the above sentence step wise as sentence goes? specially : what is -> parameterized type of a function template and how it is compared with type of call argument ?

The problem is not coding itself actually , i understanding everything and what author means to say overall but it's just i am trying to figure out meaning of every sentence and word to understand the whole perfectly and exactly.
P.S: I am gone mad or author has used some superfluous words?
Three answers:
Cubbi
2011-11-21 00:32:26 UTC
The author was describing function template argument deduction, found at §14.8.2.1[temp.deduct.call]/1 in the standard, which begins "Template argument deduction is done by comparing each function template parameter type with the type of the corresponding argument of the call", followed by five pages of excruciating detail on how exactly that happens.



The goal, quoting §14.8.3[temp.over]/1: is "for each function template to find the template argument values (if any) that can be used with that function template to instantiate a function template specialization that can be invoked with the call arguments."



"parametrized type" is simply the language-agnostic way to say "template specialization". To quote the C++ FAQ, http://www.parashift.com/c++-faq-lite/templates.html#faq-35.5 "List is a type (List) parameterized over another type (int)."



EDIT:

"Function template parameter type", in your case, is the type T, which is a template parameter type (template parameters are either types or non-types or templates) of your function template "max".



The proposed wording "function's template parameter type" doesn't work because functions don't have template parameters. You could write "function template's template parameter type" if that helps. Also, there is no such thing as "call parameter", there are call arguments.
delange
2016-12-13 09:00:47 UTC
The British education gadget has constantly been recognised by means of fact the perfect via something of the worldwide. Many babies in this worldwide are disadvantaged of a respectable education. i think of that's a super pity and clarification for shame that British faculties are churning out unappreciative scholars that evaluate it 'cool' to chat, write and style as you have exhibited. If i grew to become into an company and won an illegible interest utility written in this style, i does not even provide the applicant the main menial interest.
Rahil
2011-11-19 10:20:55 UTC
When you type something like max(1, 1.0); the program enters a "deduction process", i.e. it has to guess what function you meant. max(1, 1.0) could mean max(int,int) or max(double,double) or max(char*,char*) of course max(double,double) is probably what you meant. The program has to deduce that from the parameters (1, 1.0) which is (int,double) that one of the parameters (the int) needs to be converted into a double.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...