声明嵌套命名空间`std`是否合法C++? [英] Is it legal C++ to declare a nested namespace `std`?

查看:87

问题描述

std 命名空间在 C++ 中是特殊的,所以 ...

The std namespace is special in C++, so ...

这是合法的 C++ 吗?

Is this legal C++?

// at global scope
namespace mine {
  namespace std {
    ...
  }
}

我会说这很疯狂,但这是允许的吗?

I'd call it insane, but is it allowed?

来自标准的参考(或非参考)将不胜感激.

A reference (or non-reference) from the Standard would be appreciated.

推荐答案

reserved names 标准 17.4.3.1(及其子段落)中我找不到任何禁止使用 std 作为嵌套命名空间名称.它不是宏,不在全局命名空间中,而且似乎不符合任何禁止它的外部链接标准".

In the reserved names standard 17.4.3.1 (and its sub-paragraphs) I can't find anything that prohibits using std as a nested namespace name. It's not a macro, it's not in the global namespace, and it doesn't seem to meet any of the "external linkage criteria" that would prohibit it.

这似乎是合法的(尽管您指出这是非常不可取的).

It appears to be legal (although as you note extremely inadvisable).

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆