Vit*_*meo 6 c++ language-lawyer variadic-templates template-argument-deduction c++17
考虑以下可变参数类模板:
template <typename... Ts>
struct foo
{
template <typename... Us>
foo(Us...) { }
};
Run Code Online (Sandbox Code Playgroud)
如果我尝试以foo下列方式实例化,g ++(trunk)和clang ++(trunk)都很高兴:
auto o = foo{};
Run Code Online (Sandbox Code Playgroud)
auto o = foo();
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)error: cannot deduce template arguments for 'foo' from () auto o = foo(); ^
{}()
这也适用于适当的演绎指南:https: //godbolt.org/g/qReXpM.