c++ - 专门化 std::decay 有意义吗?

标签 c++ c++11 template-specialization c++-standard-library

我有一个代表数组引用的类(class array_ref),另一个(即保存/拥有/包含)数组(class array)。 array_ref 的行为类似于引用。

std::decay 专门化为 class array_refarray 是否有意义?

namespace std{
template<> class decay<arra_ref>{typedef array type;};
}

我还需要什么其他替代方法来告诉通用程序 arrayarray_ref 的“值类型”?

std::decay 是否用于任何 STL 算法?

最佳答案

标准库算法是否使用它并不重要。重要的是标准在 [meta.type.synop]/1 中的规定:

The behavior of a program that adds specializations for any of the templates defined in this subclause is undefined unless otherwise specified.

“本子条款”中包含所有类型特征类,包括decay。所以不要专门化它。曾经。

关于c++ - 专门化 std::decay 有意义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41029092/

相关文章:

c++ - 在套接字编程中选择在 Windows 中挂起一段时间?

c++ - 类定义和函数签名中的宏有什么用?

使用 decltype(var) 后跟内部类型 "var"时出现 C++11 编译器错误

c++ - 为什么在这个函数中返回时使用std::move

c++ - 为什么 {} 用于访问 std::hash 中的 operator()?

c++ - 对于我的std::pair特化,我应该在哪里定义运算符>>?

python & c-c++ 单元程序导致段

c++ - 是否可以在C++中将两位数字保存在无符号字符中

c++ - 参数值相等时的模板特化

c++ - 关于模板类语法