C++20 不再需要依赖作用域
C++20 No more dependent scope needed
我最近升级到 c++20
并注意到当我不将 typename
放在依赖的 cope 类型别名前面时编译器不会抛出错误,例如
using iterator = (no typename here) std::vector<int>::iterator
这现在是新的 c++20 标准的一部分还是它只是 gcc 的东西而不是所有的编译器都这样做?
这是一个 C++20 的东西:
In some contexts, only type names can validly appear. In these contexts, a dependent qualified name is assumed to name a type and no typename is required:
- A qualified name that is used as a declaration specifier in the (top-level) decl-specifier-seq of:
- a simple declaration or function definition at namespace scope;
- a class member declaration;
- a parameter declaration in a class member declaration (including friend function declarations), outside of default arguments;
- a parameter declaration of a declarator for a function or function template whose name is qualified, outside of default arguments;
- a parameter declaration of a lambda expression outside of default arguments;
- a parameter declaration of a requires-expression;
- the type in the declaration of a non-type template parameter;
- A qualified name that appears in type-id, where the smallest enclosing type-id is:
- the type in a new expression that does not parenthesize its type;
- the type-id in an alias declaration;
- a trailing return type,
- a default argument of a type template parameter, or
- the type-id of a static_cast, dynamic_cast, const_cast, or reinterpret_cast.
有关详细信息,请参阅 dependent_name#The_typename_disambiguator_for_dependent_names。
我最近升级到 c++20
并注意到当我不将 typename
放在依赖的 cope 类型别名前面时编译器不会抛出错误,例如
using iterator = (no typename here) std::vector<int>::iterator
这现在是新的 c++20 标准的一部分还是它只是 gcc 的东西而不是所有的编译器都这样做?
这是一个 C++20 的东西:
In some contexts, only type names can validly appear. In these contexts, a dependent qualified name is assumed to name a type and no typename is required:
- A qualified name that is used as a declaration specifier in the (top-level) decl-specifier-seq of:
- a simple declaration or function definition at namespace scope;
- a class member declaration;
- a parameter declaration in a class member declaration (including friend function declarations), outside of default arguments;
- a parameter declaration of a declarator for a function or function template whose name is qualified, outside of default arguments;
- a parameter declaration of a lambda expression outside of default arguments;
- a parameter declaration of a requires-expression;
- the type in the declaration of a non-type template parameter;
- A qualified name that appears in type-id, where the smallest enclosing type-id is:
- the type in a new expression that does not parenthesize its type;
- the type-id in an alias declaration;
- a trailing return type,
- a default argument of a type template parameter, or
- the type-id of a static_cast, dynamic_cast, const_cast, or reinterpret_cast.
有关详细信息,请参阅 dependent_name#The_typename_disambiguator_for_dependent_names。