为什么 std::is_copy_constructible<T&&>::value 返回 false?
Why does std::is_copy_constructible<T&&>::value return false?
对于相同类型的T
,即使is_copy_constructible<T>
是true
,is_copy_constructible<T&&>
似乎也是false
。我已经用gcc和clang测试过了,得到了相同的结果。这是预期的行为吗?标准在哪里定义这一点?这种行为的原因是什么?
编译时出现错误"int&& doesn't work"
:的示例代码
#include <type_traits>
int main() {
static_assert(std::is_copy_constructible<int>::value, "int doesn't work");
static_assert(std::is_copy_constructible<int&>::value, "int& doesn't work");
static_assert(std::is_copy_constructible<int&&>::value, "int&& doesn't work");
return 0;
}
我在尝试对模板参数创建约束以确保模板仅适用于可复制构造类型时遇到了这种情况。我是否需要为r值引用类型创建一个特例,以便让我的模板使用r值引用来复制可构造类型?
is_copy_constructible<T>
定义为is_constructible<T, const T&>
。对于T = int &&
,后者变为is_constructible<int&&, int&>
,这显然是错误的:
int & f();
int && r(f()); // ill-formed
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- EASTL矢量<向量<int>>连续的
- 为什么static_assert错误:即使我传递常量"expression must have a constant value"?
- 为什么我会" void value not ignored as it ought to be"?
- 方法错误"not all control paths return a value"和方法不返回值
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 如何在 c++ 中理解这样的代码 [request->headers().Method()->value().getStringView())]
- std::<key-value>不同类型的对向量
- c++ visual studio 64bit | save registers value
- 初始化数组、"memset"或" {//value} "的最佳方法是什么?
- 如何解决类成员函数中的"return a value"错误?
- bsoncxx: document::view vs document::value
- .value( "key" , default) 不适用于空的 json 对象吗?
- 如何在C++中设置演员的"Render Custom Depth Pass"和"Depth Stencil Value"?
- Qt 错误:QSqlQuery::value:尝试从表中检索统计信息时未定位在有效记录上 (QComboBox)
- 马洛克会在 C++17 年返回"invalid pointer value"吗?
- 如何将 v8::FunctionCallbackInfo<v8::Value> 数组从一个隔离复制到另一个隔离?
- std::value templated 方法的函数使用 clang 和 g++ 进行编译,但不使用 msvc 进行编译
- 无法使用 auto 来参数化true_type来检测 T::value()
- 为什么使用 "++value"会导致 -842150449?