使用嵌套的 std 和 posix 命名空间是否未定义?
Is using nested std and posix namespaces undefined?
根据 Extending the std
namespace and [namespace.constraints] 上的(现已失效)Whosebug 文档:
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std
or to a namespace within namespace std unless otherwise specified.
和
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace posix
or to a namespace within namespace posix
unless otherwise specified. The namespace posix
is reserved for use by ISO/IEC 9945 and other POSIX standards.
这些规则是否仅适用于 global std
和 posix
命名空间,或者以下内容是否也未定义:
namespace HelloWorld {
namespace std {
void terminate();
}
}
也许是因为我的母语是英语,但是这些规则的措辞在这方面似乎有点模糊。
这确实是一个有点晦涩的英语规则。您会看到规则讨论了命名空间 std
中的 a 命名空间。为什么我们不讨论 "a namespace std
" 或 "the namespace std
"?这是因为 std
是该命名空间的(唯一)名称。比较 "a president"、"the president"、"president Trump"。
所以是的,namespace std
唯一地引用了那个 top-level 命名空间。
根据 Extending the std
namespace and [namespace.constraints] 上的(现已失效)Whosebug 文档:
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace
std
or to a namespace within namespace std unless otherwise specified.
和
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace
posix
or to a namespace within namespaceposix
unless otherwise specified. The namespaceposix
is reserved for use by ISO/IEC 9945 and other POSIX standards.
这些规则是否仅适用于 global std
和 posix
命名空间,或者以下内容是否也未定义:
namespace HelloWorld {
namespace std {
void terminate();
}
}
也许是因为我的母语是英语,但是这些规则的措辞在这方面似乎有点模糊。
这确实是一个有点晦涩的英语规则。您会看到规则讨论了命名空间 std
中的 a 命名空间。为什么我们不讨论 "a namespace std
" 或 "the namespace std
"?这是因为 std
是该命名空间的(唯一)名称。比较 "a president"、"the president"、"president Trump"。
所以是的,namespace std
唯一地引用了那个 top-level 命名空间。