Path: csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 20 Feb 2016 15:20:05 -0600 Return-Path: Sender: std-cpp-request@vandevoorde.com Approved: austern@google.com Message-ID: Newsgroups: comp.std.c++ From: Christoph Schulz Subject: C++11: Template argument deduction, partial ordering, and trailing parameter packs Organization: unknown Content-Type: text/plain; charset="UTF-8" X-Original-Date: Wed, 17 Feb 2016 17:19:11 +0100 X-Submission-Address: std-cpp-submit@vandevoorde.com Date: Sat, 20 Feb 2016 15:19:09 CST Lines: 62 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-KfjVlPY0HHSkDn1vktiaga2fdZVzTzj2htgwZiXgM+Y1Hab0lxjT//wJrC3lQkRzJT4bn262kA/Wo+X!+fRYJcKzsI577WJk2optmwziji3ZRqgTwENMVBan29G4a6cjOtBAG3KFngw= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3024 X-Received-Bytes: 3136 X-Received-Body-CRC: 2218137774 Xref: csiph.com comp.std.c++:783 Hello, I read §14.8.2.1, §14.8.2.4, and §14.8.2.5 multiple times but did not find a convincing argumentation why the second of the following two function templates is more specialized for the given argument than the first one: ========= %< ========= #include #include template struct X {}; // #1 template int f(X x) { return I + f(X{}); } // #2 template int f(X) { return I; } int main() { std::cout << f(X<1>{}) << std::endl; // selects #2 } ========= %< ========= The compiler I used (g++ 4.9.3) has no problems compiling this code. But I don't understand why. For both #1 and #2, "I" can be deduced to be "1", and in #1, "Ints..." can be deduced to be an empty list of int values, making the parameter type be "X<1>" in both cases. (This can be "proven" by removing #1 or #2 from the overload set by #if 0 ... #endif, and seeing the code compile successfully in both cases.) So, according to §13.3.3/1, partial ordering of function templates should disambiguate this case. But which rule makes #2 more specialized than #1? In this situation, §14.8.2.5/9 seems to apply, but the sentence - if P does not contain a template argument corresponding to Ai then Ai is ignored; seems to support the interpretation that #1 can be deduced from #2. Can anybody shed some light on it? I'm sure that I overlooked something... Or does g++ behave simply wrong? Best regards, -- Christoph Schulz [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]