C++ 为什么'std::is_constructible_v<;int[2],int,int>;==假的`
可复制示例:C++ 为什么'std::is_constructible_v<;int[2],int,int>;==假的`,c++,arrays,c++17,C++,Arrays,C++17,可复制示例: #include <type_traits> static_assert(std::is_constructible_v<int[2], int, int>, "fails against my expectations"); #包括 静态断言(std::is_constructible_v,“与我的期望不符”); 我用clang 5和gcc 7对此进行了测试。std::is_constructible的目的和定义是检查指定类型的对象是否可以按照以下方式
#include <type_traits>
static_assert(std::is_constructible_v<int[2], int, int>, "fails against my expectations");
#包括
静态断言(std::is_constructible_v,“与我的期望不符”);
我用clang 5和gcc 7对此进行了测试。std::is_constructible的目的和定义是检查指定类型的对象是否可以按照以下方式构造:
T obj(std::declval<Args>()...);
tobj(std::declval()…);
对于一个数组来说,上面的内容并不是很好的格式。数组没有任何构造函数,它是一个聚合,应该用聚合初始化来初始化。std::is_constructible的目的和定义是检查指定类型的对象是否可以按照以下方式构造:
T obj(std::declval<Args>()...);
tobj(std::declval()…);
对于一个数组来说,上面的内容并不是很好的格式。数组没有任何构造函数,它是一个聚合,应该使用聚合初始化进行初始化。来自:
如果T是一个对象或引用类型,并且变量定义为T obj(std::declval),那么聚合初始化在这里起作用,而不是构造。来自:
如果T是一个对象或引用类型,变量定义为
T obj(std::declval),那么聚合初始化在这里起作用,而不是构造。为什么您希望它为真?数组没有构造函数。From:“IfT
是一个对象或引用类型,变量定义为T obj(std::declval()…);
格式正确,提供的成员常量值等于true
。在所有其他情况下,值为false
“int-obj[2](int,int)
定义不明确。不要将构造与聚合初始化混淆。为什么希望它为true?数组没有构造函数。从:“如果T
是对象或引用类型,并且变量定义T obj(std::declval());
格式正确,则提供的成员常量值等于true
。在所有其他情况下,值为false
”int obj[2](int,int)
定义不明确。不要将构造与聚合初始化混淆。