`using namespace std::placeholders;` 不符合规范吗?
Is `using namespace std::placeholders;` non-conformant?
来自 § 2.10.3.2:
Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
考虑到这一点,这个程序是否符合标准?因为它使 _1
等可从全局名称空间获得?还是可以因为 std::placeholders
被认为是 "implementation"?还是因为 _1
实际上不在全局命名空间中?还有别的吗?
using namespace std::placeholders;
int main(){}
我觉得这个程序很好。严格来说,using 指令不会将任何名称放入名称空间 - 它使名称可以通过名称查找访问,但实际上并没有使它们成为包含 using 指令的名称空间的成员。
引用 C++11, 7.3.4:
2 A using-directive specifies that the names in the nominated namespace can be used in the scope in which the
using-directive appears after the using-directive. During unqualified name lookup (3.4.1), the names appear
as if they were declared in the nearest enclosing namespace which contains both the using-directive and the
nominated namespace. [ Note: In this context, “contains” means “contains directly or indirectly”. —end
note ]
3 A using-directive does not add any members to the declarative region in which it appears. ...
注意语言 "can be used," "as if they were declared" 等。没有提到实际上使名称成为不同名称空间的成员。
关于通过限定名称访问,3.4.3.2(命名空间的限定名称查找)说:
2 For a namespace X
and name m
, the namespace-qualified lookup set S(X,m) is defined as follows: Let
S'(X,m) be the set of all declarations of m
in X
and the inline namespace set of X
(7.3.1). If S'(X,m) is not
empty, S(X,m) is S'(X,m); otherwise, S(X,m) is the union of S(Ni,m) for all namespaces Ni nominated
by using-directives in X
and its inline namespace set.
即 using 指令的单独规则。
我由此得出结论,using 指令不会使任何名称成为命名空间的成员,因此不会触发 _
全局命名空间规则,也不会发生未定义的行为。
来自 § 2.10.3.2:
Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
考虑到这一点,这个程序是否符合标准?因为它使 _1
等可从全局名称空间获得?还是可以因为 std::placeholders
被认为是 "implementation"?还是因为 _1
实际上不在全局命名空间中?还有别的吗?
using namespace std::placeholders;
int main(){}
我觉得这个程序很好。严格来说,using 指令不会将任何名称放入名称空间 - 它使名称可以通过名称查找访问,但实际上并没有使它们成为包含 using 指令的名称空间的成员。
引用 C++11, 7.3.4:
2 A using-directive specifies that the names in the nominated namespace can be used in the scope in which the using-directive appears after the using-directive. During unqualified name lookup (3.4.1), the names appear as if they were declared in the nearest enclosing namespace which contains both the using-directive and the nominated namespace. [ Note: In this context, “contains” means “contains directly or indirectly”. —end note ]
3 A using-directive does not add any members to the declarative region in which it appears. ...
注意语言 "can be used," "as if they were declared" 等。没有提到实际上使名称成为不同名称空间的成员。
关于通过限定名称访问,3.4.3.2(命名空间的限定名称查找)说:
2 For a namespace
X
and namem
, the namespace-qualified lookup set S(X,m) is defined as follows: Let S'(X,m) be the set of all declarations ofm
inX
and the inline namespace set ofX
(7.3.1). If S'(X,m) is not empty, S(X,m) is S'(X,m); otherwise, S(X,m) is the union of S(Ni,m) for all namespaces Ni nominated by using-directives inX
and its inline namespace set.
即 using 指令的单独规则。
我由此得出结论,using 指令不会使任何名称成为命名空间的成员,因此不会触发 _
全局命名空间规则,也不会发生未定义的行为。