- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
允许用户向 std
命名空间添加显式特化。但是,有一些模板是明确禁止我专门研究的。
哪些模板可以专攻,哪些不能专攻?
最佳答案
粗略地引用标准:
numeric_limits
不应专门用于非算术标准类型(例如 complex<T>
)
“[S] shared_ptr
的专用化应为 CopyConstructible、CopyAssignable 和 LessThanComparable [并且] 可转换为 bool
。”
“weak_ptr
的特化应该是 CopyConstructible 和 CopyAssignable。”
"[T]模板特化[std::hash
]应满足类模板哈希的要求。"
<type_traits>
中的任何内容:“除非另有说明,否则为本子条款中定义的任何类模板添加特化的程序的行为是未定义的。” (只有 common_type
的一些特化是明确允许的)
语言环境具有某些必需的特化。
istreambuf_iterator
的所有专业应该有一个普通的复制构造函数、一个 constexpr 默认构造函数和一个普通的析构函数。
“为浮点、 double 或长 double 以外的任何类型实例化类模板 complex
的效果未指定。”我认为这意味着定义这样的其他专业是没有意义的。
“atomic
模板的特化和实例化应具有已删除的复制构造函数、已删除的复制赋值运算符和 constexpr 值构造函数。”
“类模板 unary_function
和 binary_function
已弃用。程序不得声明这些模板的特化。”
当然还有首要条款 17.6.4.2.1,第 1 句(感谢 @sehe 和 @curiousguy):
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to anamespace within namespace std unless otherwise specified. A program may add a template specializationfor any standard library template to namespace std only if the declaration depends on a user-defined typeand the specialization meets the standard library requirements for the original template and is not explicitlyprohibited.
第二句:
The behavior of a C++ program is undefined if it declares
an explicit specialization of any member function of a standard library class template, or
an explicit specialization of any member function template of a standard library class or class template, or
an explicit or partial specialization of any member class template of a standard library class or class template.
A program may explicitly instantiate a template defined in the standard library only if the declarationdepends on the name of a user-defined type and the instantiation meets the standard library requirementsfor the original template.
关于c++ - 我可以和不可以专注于 std 命名空间吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8513417/
我有一个 Collection View 并以这样一种方式排列它,即在屏幕的一侧有一个单独的列,并且根据焦点中的集合项替换内容。 如果对某个项目的关注超过 0.5 秒,我希望能够换出内容。 这是我目前
这是一种经常出现的情况,对我来说永远不会太容易。我想我会问其他人如何处理它。 想象一下,如果 demo=60 命令行参数的处理是这样完成的: if DemoOptionSpecified() {
我是一名优秀的程序员,十分优秀!