Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!209.197.12.242.MISMATCH!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Ruben Safir Newsgroups: comp.lang.c++ Subject: Re: Template argument determination Date: Thu, 26 May 2011 16:12:55 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 106 Message-ID: References: NNTP-Posting-Host: www2.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1306426375 6813 96.57.23.82 (26 May 2011 16:12:55 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 26 May 2011 16:12:55 +0000 (UTC) X-Blackjet: Blackjet is a Yankee Fan X-DRMisTHEFT: Use GNU Linux today X-From: A Dark Cloud X-LOCATION: Brooklyn NY - Forget abou' it! X-NYLXS: Really - yah think computers are supposed to be broken? User-Agent: Pan/0.133 (House of Butterflies) Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:5627 On Wed, 25 May 2011 12:37:30 -0500, A. Bolmarcich wrote: > I did not say that conversion by construtor was used when deducing > template arguments. It is used after the specific function to call has > been determined. Determining the specific function to call may involve > instantating function templates using deduced template arguments. > I understand this. > I snipped from your post all but what you wrote and explained the > difference between using > > foo(42) > > and > > foo(42) > > in the example you wrote. With foo(42), the function template argument > was neither explicitly specified nor deduced, and the template was not > instantiated. > I don't understand this. >>> On 2011-05-24, Ruben Safir wrote: >>> >>>> > Bingo - thanks for taking the time to give me this explanation. >>>> > But its not capable of doing this implicit conversation unless T is >>>> > defined as an int. The compiler couldn't deduce this otherwise. >>> A compiler should do the implicit conversion as long as the parameter >>> type has an accessible >>> >>> - non-explicit constructor that can take a value of type T as the only >>> argument, or >>> - conversion function of the form: operator T() >> >> Let me explain what I am reading here. Ruben: "compiler cannot use any >> conversion unless T is defined". You: "A compiler should do the >> conversion." - as if it doesn't matter whether type is deduced or not. > Now you totally lost me. I find when I read the text books, this often happens. I was reading the section when Templates are instantated, and i similarly confuse the heck out of me. > What Ruben wrote was: "But its not capable of doing this implicit > conversion unless T is defined as an int." Your reading missed some of > the words Ruben wrote. I wrote that an implicit conversion from > function arguments to function parameters should be done even if T is > defined as something other than an int. See the language started to get very confusing. We have template parameters, function parameters, template arguments, function arguments...my head is swiming and to make it harder, you keep substituting structs for classes. > For example, > > template > struct List { > List() {} > }; > > template > struct X { > X(T x) {} > X(List x) {} > }; > > template > void foo(X x) {} > > int main() { > List il; > > foo(42); > foo >(il); > } > > For the call foo(42), T is defined as an int and the signature of > the instantiated function is > > foo(X) > > As part of calling that function, the argument value 42 is implicitly > converted to the X parameter, using the X(int) constructor. > > For the call foo >(il), T is defined as a List and the > signature of the instantiated function is > > foo >(X >) > > As part of calling that function, the argument value il is implicitly > converted to the X > parameter, using the X(List) > constructor. In this case, a conversion by constructor is done even > though T is not defined as an int. > > [snip]