Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #37065
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: template variables |
| Date | 2015-07-13 22:11 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <mo15vm$vae$1@dont-email.me> (permalink) |
| References | <0fe31d7f-95b8-4218-9a01-1ef61d828bbd@googlegroups.com> |
On 13-Jul-15 8:39 PM, Doug Mika wrote: > If a template variable type can be deduced from the variables provided in the > constructor of a template class, then is it needed? I thought it wasn't, but > when in the following program (below) I replace the line: > > map<int, string, function<bool(const int&, const int&)>> > mapIntToString1(ReverseSort<int>); > > with: > > map<int, string> > mapIntToString1(ReverseSort<int>); > > the code no longer compiles? Why isn't the compiler able to deduce from the > submitted function ReverseSort<int> that the template variable type is > bool(*)(const int&, const int&)? Is the compiler only smart enough to deduce > this for template functions? The language was not designed to support this, but the need has become more and more manifest, with all kinds of "make" functions being defined. There is some discussion at SO, at <url: http://stackoverflow.com/questions/29677505/why-cant-constructors-deduce-template-arguments> There is a current proposal to support this, N4471, referenced from the SO discussion, <url: http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4471.html> and it lists some of the difficulties, in particular that * The constructor argument type can be indirectly defined in terms of a template parameter, which then is difficult to deduce. I'm not sure I agree with the comment in the "inject class name" example though. This looks like still a pretty rough draft that needs to be ironed out. I can't see that it will make C++17. But never say never! :) Cheers & hth., - Alf -- Using Thunderbird as Usenet client, Eternal September as NNTP server.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
template variables Doug Mika <dougmmika@gmail.com> - 2015-07-13 11:39 -0700 Re: template variables Victor Bazarov <v.bazarov@comcast.invalid> - 2015-07-13 15:20 -0400 Re: template variables "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2015-07-13 22:11 +0200
csiph-web