Title
Template argument deduction from function return types
Status
c++11
Section
13.9.4 [temp.expl.spec]
Submitter
Richard Corden

Created on 2007-02-16.00:00:00 last changed 130 months ago

Messages

Date: 2010-08-23.00:00:00

[Voted into WP at August, 2010 meeting.]

Date: 2010-03-15.00:00:00

Proposed resolution (March, 2010):

This issue is resolved by the resolution of issue 873.

Date: 2010-02-15.00:00:00

Proposed resolution (February, 2010):

Add the following paragraph at the end of 13.7.7 [temp.fct]:

In a declaration that names a specialization of a function template, template arguments can be deduced from the function type. [Note: this can occur in the context of an explicit specialization, an explicit instantiation, or a friend declaration. —end note] The function template's function type and the declared type are used as the types of P and A and the deduction is done as described in 13.10.3.6 [temp.deduct.type].
Date: 2008-09-15.00:00:00

Notes from the September, 2008 meeting:

The proposed resolution is probably more than is needed. Instead of a complete new section, the material could become a paragraph in 13.7.7 [temp.fct].

Date: 2008-03-15.00:00:00

Proposed resolution (March, 2008):

  1. Insert the following as a new subsection after 13.10.3.6 [temp.deduct.type]:

  2. 14.9.2.6 Deducing template arguments in a declaration that names a specialization of a function template [temp.deduct.funcdecl]

    Template arguments can be deduced from the function type specified when declaring a specialization of a function template. [Note: this can occur in the context of an explicit specialization, an explicit instantiation, or a friend declaration. —end note] The function template's function type and the declared type are used as the types of P and A, and the deduction is done as described in 13.10.3.6 [temp.deduct.type].

  3. Change 13.9.4 [temp.expl.spec] paragraph 11 as follows:

  4. A trailing template-argument can be left unspecified in the template-id naming an explicit function template specialization provided it can be deduced from the function argument type (14.9.2.6 [temp.deduct.funcdecl])...
Date: 2007-02-16.00:00:00

It does not appear that the following example is well-formed, although most compilers accept it:

    template <typename T> T foo();
    template <> int foo();

The reason is that 13.9.4 [temp.expl.spec] paragraph 11 only allows trailing template-arguments to be omitted if they “can be deduced from the function argument type,” and there are no function arguments in this example.

13.9.4 [temp.expl.spec] should probably say “function type” instead of “function argument type.” Also, a subsection should probably be added to 13.10.3 [temp.deduct] to cover “Deducing template arguments from declarative contexts” or some such. It would be essentially the same as 13.10.3.3 [temp.deduct.funcaddr] except that the function type from the declaration would be used as the type of P.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetstatus: wp -> fdis
2010-11-29 00:00:00adminsetstatus: dr -> wp
2010-08-23 00:00:00adminsetmessages: + msg2930
2010-08-23 00:00:00adminsetstatus: ready -> dr
2010-03-29 00:00:00adminsetmessages: + msg2574
2010-03-29 00:00:00adminsetstatus: review -> ready
2010-02-16 00:00:00adminsetmessages: + msg2565
2010-02-16 00:00:00adminsetstatus: drafting -> review
2008-10-05 00:00:00adminsetmessages: + msg1785
2008-10-05 00:00:00adminsetstatus: review -> drafting
2008-05-18 00:00:00adminsetmessages: + msg1640
2008-05-18 00:00:00adminsetstatus: drafting -> review
2007-05-06 00:00:00adminsetstatus: open -> drafting
2007-02-16 00:00:00admincreate