Topic: Defect Report: References to functions are ignored in template argument deduction
Author: iltchenko@yahoo.com (Andrei Iltchenko)
Date: 13 Jul 01 12:47:10 GMT Raw View
[Moderator's note: this defect report has been
forwarded to the C++ committee. -moderator.]
Section: 14.8.2.4 - Deducing template arguments from a type
[temp.deduct.type]
Submitter: Andrei Iltchenko (iltchenko@yahoo.com)
Paragraph 9 of the section 14.8.2.4 [temp.deduct.type] enumerates the
forms that the types P and A need to have in order for template
argument deduction to succeed.
For P denoting a pointer to function the paragraph lists the following
forms as allowing for template argument deduction:
type(*)(T)
T(*)()
T(*)(T)
On the other hand, no provision has been made to accommodate similar
cases for references to funtions, which in light of the wording of
14.8.2.4 [temp.deduct.type] paragraph 11 means that the program below
is ill-formed (some of the C++ compilers do not reject it however):
template<typename Arg, typename Result, typename T>
Result foo_r(Result(& rf)(Arg), T x)
{ return rf(Arg(x)); }
template<typename Arg, typename Result, typename T>
Result foo_p(Result(* pf)(Arg), T x)
{ return pf(Arg(x)); }
#include <iostream>
int show_arg(char c)
{
std::cout << c << ' ';
if(std::cout) return 0;
return -1;
}
int main()
{
// The deduction
int (& rf1)(int(&)(char), double) = foo_r; // shall fail here
// While here
int (& rf2)(int(*)(char), double) = foo_p; // it shall succeed
return rf2(show_arg, 2);
}
Suggested resolution:
In the list of allowable forms for the types P and A (paragraph 9 of
the section 14.8.2.4 [temp.deduct.type]) replace
type(*)(T)
T(*)()
T(*)(T)
by
type(T)
T()
T(T)
Given the latitude provided by paragraph 10 of the section 14.8.2.4
[temp.deduct.type], this will make it possible for template argument
deduction to be done against pointers and references to functions
alike.
Regards,
Andrei Iltchenko.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]