错误:无法通过`..`传递非普通可复制类型的对象
error: cannot pass objects of non-trivially-copyable type through `...`
我有一个类unit
,它具有属性
std::is_trivial<unit>::value; // true
std::is_trivially_copyable<unit>::value; // true (on compilers which have this trait)
我想把unit
的向量作为元组传递,例如
using geodeticTuple = std::tuple<unit, unit, unit>;
我需要这些向量可以传递到使用不同类型参数的转换函数中,例如
someOtherType convert(const geodeticTuple& point, const geodeticTuple& origin)
或
someOtherType convert(const geodeticTuple& point, ...)
使用MSVC2015,这完全可以,但使用gcc-4.9.3,我得到了错误:
错误:无法通过
...
传递非普通可复制类型const geodeticTuple {aka const struct std::tuple<unit, unit, unit>}
的对象
由于gcc-4.9.3不支持is_trivially_xxx
风格类型特征,我很难理解为什么会失败。
琐碎类型的元组在琐碎方面是不可复制的吗?
tuple
的复制/移动赋值运算符需要对引用类型进行特殊处理,因此在一般情况下必须由用户提供。
由于该标准不需要琐碎的可复制性,因此实现者是否需要额外的时间来提供这种保证(这需要添加额外的专业化)是一个QoI问题。
相关文章:
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果可推导类型上有替换,可变参数模板类型推导会使编译器崩溃
- 简单可复制与可简单复制
- reinterpret_cast,只读访问,简单的可复制类型,会出什么问题?
- 可变参数宏:无法通过"..."传递非平凡可复制类型的对象
- 我可以隐式地创建一个琐碎的可复制类型吗
- 是std::memcpy在不同的可复制类型之间的未定义行为
- 防御性地应用 std::move 到平凡可复制的类型是否不可取
- 为什么 std::function 本身是可复制构造的类型?
- 错误:无法通过'...'传递非平凡可复制类型的对象'class boost::filesystem::path'
- 使用临时存储区复制普通的可复制类型:允许吗
- 在成员容器中复制具有仅可移动但可克隆类型的构造函数
- 非平凡可复制类型的值表示
- 类型 traits,用于检查参数包中的所有类型是否都是可复制构造的
- 交换包含非一般可复制类型的“std::aligned_storage”实例-未定义的行为
- 错误:无法通过`..`传递非普通可复制类型的对象
- 无法传递非普通可复制类型“const class mysqlpp::String”的对象
- 将std::memcpy用于非平凡可复制类型的对象
- 不可复制类型的整数可索引RAII容器
- 是否有任何库为非默认可构造的不可复制类型提供容器