在使用declytype推断类型时删除CV限定符
Removing CV qualifiers when deducing types using declytype
我有一个常量声明如下:
const auto val = someFun();
现在我想要另一个变量具有相同类型的'val',但没有常量规格。
decltype(val) nonConstVal = someOtherFun();
// Modify nonConstVal, this is error when using decltype
当前decltype保留常量。怎么剥?
From <type_traits>
可以在c++ 14中使用:
std::remove_cv_t<decltype(val)> nonConstVal = someOtherFun();
或c++ 11
std::remove_cv<decltype(val)>::type nonConstVal = someOtherFun();
演示相关文章:
- 将数组的地址分配给变量并删除
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- C/C++编译器通常会删除重复的库吗
- 从链接列表c++中删除一个项目
- C++如何通过用户输入删除列表元素
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 是否需要删除包含对象的"pair"?
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何在自删除后将对象设置为nullptr
- 迭代时从向量和内存中删除对象
- 使用函数"remove"删除重复元素
- 如何从多映射中删除特定的重复项
- 运算符C++ "delete []"仅删除 2 个前值
- 删除指向指针的指针是运行时错误吗
- 将指针设置为"nullptr"并不能防止双重删除?
- 为什么示例代码访问IUnknown中已删除的内存
- 为什么在某些情况下从函数返回类型中删除 cv 限定符?
- 模板引用折叠正在删除常量引用返回类型的cv限定符
- 如果cv::Mat是用用户分配的数据构建的,那么它会负责删除它吗
- 在使用declytype推断类型时删除CV限定符