为什么std::is_copy_constructible的行为不符合预期
Why does std::is_copy_constructible not behave as expected?
#include <type_traits>
int main()
{
std::is_constructible_v<int&, const int&>; // false, as expected.
std::is_copy_constructible_v<int&>; // true, NOT as expected!
}
根据cppref:
如果T是对象或引用类型,并且变量定义Tobj(std::declval()…);成型良好,提供构件等于true的常数值。在所有其他情况下,value都是false。
std::is_copy_constructible_v<int&>
应该给出与std::is_constructible_v<int&, const int&>
相同的结果;然而,clang 7.0
给出了如上所示的不同结果。
此行为是否符合C++标准
如果T不是可引用类型(即,可能是cv限定的void或具有cv限定符seq或ref限定符的函数类型),则提供等于false的成员常数值。否则,提供一个等于
std::is_constructible<T, const T&>::value
的成员常数值。
因此,这里的is_copy_constructible<T>::value
与std::is_constructible<T, const T&>::value
相同。
所以在你的情况下:
CCD_ 7将与CCD_ 8相同。
参见DEMO
相关文章:
- 将 QByteArray 转换为无符号短:不符合预期
- 为什么此模板函数的行为不符合预期?
- 为什么 std::basic_ostream::运算符<<不符合 CONST 资格?
- std::vector 构造initializer_list的行为不符合预期
- C++使用 LZ4 进行压缩,压缩信息不符合预期
- 为什么 std::future::wait_for 的行为不符合预期?
- Seekg 的行为不符合预期
- Int 附加到字符,行为不符合我的预期
- NDK r16b std::istringstream 的行为不符合预期
- 为什么std::is_copy_constructible的行为不符合预期
- 我的代码到底在哪里不符合键和值类型的规范
- 如果库的包含路径设置不符合预期,如何引发编译错误
- 为什么 [std::is_move_assignable] 的行为不符合预期?
- 代码片段在某些情况下有效,但不符合预期,为什么
- 对指针行为不符合预期行为的 const 引用
- 字节不符合记忆映射和对文件进行排序
- srand() 范围不符合预期的 C++
- 简单的字符串输出不符合预期(出现换行符)
- 为什么根据 C++11 标准,std::seed_seq是不可复制的,为什么 gcc/clang 不符合?
- 如果没有c++11,易编程8.91就不符合要求