Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #68273
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Template argument deduction mystery |
| Date | 2019-09-07 21:28 +0200 |
| Message-ID | <gtiemvFoelvU1@mid.individual.net> (permalink) |
| References | (3 earlier) <rohcF.533208$on8.458387@fx46.iad> <20190906145510.4c03182d29e071b060cb8ad9@cvine--nospam--.freeserve.co.uk> <OTFcF.511763$tG2.425205@fx48.iad> <20190907152518.13d08d857bf2360dcd972522@cvine--nospam--.freeserve.co.uk> <ql0ufs$1pup$1@adenine.netfront.net> |
On 2019-09-07 at 20:55, Juha Nieminen wrote:
> Chris Vine <chris@cvine--nospam--.freeserve.co.uk> wrote:
>> As I read it, he asked about the specialization of std::greater<void>
>> which allows type deduction in its call operator. That was made
>> available in C++14.
>
> I was, in fact, asking about both things.
>
> It was completely mysterious to me how exactly std::greater would
> know that it was supposed to be comparing doubles, when nowhere in
> its instantiation it's told that. I didn't know that it has a
> specialization for void that works for exactly this kind of situation.
>
> It's also a bit unclear to me how it works without the empty <>
> brackets. I know it's related to C++ automatic template type
> deduction, but it's unclear to me how it works in this case.
> Curiously, it appears that it works without any explicit deduction
> guides. It works for the mere reason that the default template
> parameter for std::greater is void.
>
> The rules of automatic template parameter type deduction are still
> a bit unclear to me.
>
The possiblity of omitting an empty <> is just mentioned in passing,
while decribing "Explicit template argument specification":
"Trailing template arguments that can be deduced or obtained from
default template-arguments may be omitted from the list of explicit
template-arguments. A trailing template parameter pack ([temp.variadic])
not otherwise deduced will be deduced as an empty sequence of template
arguments. If all of the template arguments can be deduced, they may all
be omitted; in this case, **the empty template argument list <> itself
may also be omitted.**"
http://eel.is/c++draft/temp.arg.explicit#4
Not obvious at all, if you happened to skip over the last part of this
sentence. :-)
Bo Persson
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Template argument deduction mystery Juha Nieminen <nospam@thanks.invalid> - 2019-09-04 13:55 +0000
Re: Template argument deduction mystery Ian Collins <ian-news@hotmail.com> - 2019-09-05 07:16 +1200
Re: Template argument deduction mystery Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-05 03:03 +0200
Re: Template argument deduction mystery Juha Nieminen <nospam@thanks.invalid> - 2019-09-05 21:50 +0000
Re: Template argument deduction mystery Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-09-05 20:04 -0400
Re: Template argument deduction mystery Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2019-09-06 14:55 +0100
Re: Template argument deduction mystery Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-09-06 23:56 -0400
Re: Template argument deduction mystery Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2019-09-07 15:25 +0100
Re: Template argument deduction mystery Juha Nieminen <nospam@thanks.invalid> - 2019-09-07 18:55 +0000
Re: Template argument deduction mystery Bo Persson <bo@bo-persson.se> - 2019-09-07 21:28 +0200
Re: Template argument deduction mystery Ian Collins <ian-news@hotmail.com> - 2019-09-08 12:29 +1200
Re: Template argument deduction mystery Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2019-09-07 23:06 +0100
Re: Template argument deduction mystery Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-09-07 18:35 -0400
csiph-web