我有一个类unit
, 具有属性
std::is_trivial<unit>::value; // true
std::is_trivially_copyable<unit>::value; // true (on compilers which have this trait)
我想传递的是 unit
的 vector 作为元组,例如
using geodeticTuple = std::tuple<unit, unit, unit>;
我需要将这些 vector 传递给使用不同类型参数的转换函数,例如
someOtherType convert(const geodeticTuple& point, const geodeticTuple& origin)
或
someOtherType convert(const geodeticTuple& point, ...)
使用 MSVC2015,这完全没问题,但是使用 gcc-4.9.3,我收到错误:
error: cannot pass objects of non-trivially-copyable type
const geodeticTuple {aka const struct std::tuple<unit, unit, unit>}
through...
因为 gcc-4.9.3 不支持 is_trivially_xxx
样式类型特征,我无法理解为什么会失败。
普通类型的元组不是普通可复制的吗?
最佳答案
tuple
的复制/移动赋值运算符需要对引用类型进行特殊处理,因此在一般情况下它们必须由用户提供。
由于该标准不需要简单的可复制性,因此实现者是否竭尽全力提供该保证(这将需要添加额外的特化)是一个 QoI 问题。
关于c++ - 错误 : cannot pass objects of non-trivially-copyable type through `...` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36625317/