Declaring a member function with a typedef coming from a metafunction

后端 未结 1 741
天命终不由人
天命终不由人 2021-01-05 08:13

Consider the following code:

template 
struct Foo_s {
    using type = void();
};

template 
using Foo_u = void();

template 

        
相关标签:
1条回答
  • 2021-01-05 08:38

    [temp.spec]/8:

    If a function declaration acquired its function type through a dependent type without using the syntactic form of a function declarator, the program is ill-formed.

    This makes your last line decidedly ill-formed. Which makes sense, since, as in other cases of dependent constructs, we don't want the meaning of a phrase to depend too strongly on template arguments.

    However, [dcl.fct]/13:

    A typedef of function type may be used to declare a function but shall not be used to define a function.

    This makes your first three lines well-formed---the first two directly, and for the third one, note that

    When a template-id refers to the specialization of an alias template, it is equivalent to the associated type obtained by substitution of its template-arguments for the template-parameters in the type-id of the alias template.

    by [temp.alias].

    0 讨论(0)
提交回复
热议问题