Alias template, partial specialization and the invalid parameter type void

前端 未结 1 2025
悲哀的现实
悲哀的现实 2021-01-04 13:10

Consider the following code:

template
struct S;

template
struct S { };

template         


        
相关标签:
1条回答
  • 2021-01-04 14:01

    From [dcl.fct], emphasis mine:

    A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list. Except for this special case, a parameter shall not have type cv void.

    In this case, Args... is a dependent type pack, so void is not allowed there. This idea is repeated in a note in [temp.deduct]:

    [ Note: Type deduction may fail for the following reasons:
    — [...]
    — Attempting to create a function type in which a parameter has a type of void, or in which the return type is a function type or array type.
    — [...]
    —end note ]

    Note that S<void(void)> compiles since void(void) is non-dependent and is equivalent to void(), so Ret(Args...) is never deduced to have void in the parameter list - it's deduced with Args... empty.


    At least there's a simple workaround in that you can just write Alias<>.

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