Using 'void' template arguments in C++

前端 未结 5 1078
执念已碎
执念已碎 2020-12-09 09:54

Take the following minimal example:

using Type1 = std::function;

template 
using Type2 = std::function;

         


        
5条回答
  •  既然无缘
    2020-12-09 10:04

    Several answers already explain the rationale. To add to those answers, the specification says (C++11 §8.3.5[dcl.func]/4):

    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 your Type2 example, the T in void(T) is a dependent type--it depends on a template parameter.

提交回复
热议问题