error: cannot pass objects of non-trivially-copyable type through `...`
error: cannot pass objects of non-trivially-copyable type through `...`
我有一个 class 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,我收到错误:
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
的copy/move赋值运算符需要对引用类型进行特殊处理,因此一般情况下必须由用户提供。
由于该标准不要求简单的可复制性,因此实施者是否竭尽全力提供该保证(这将需要添加额外的专业化)是一个 QoI 问题。
我有一个 class 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,我收到错误:
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
的copy/move赋值运算符需要对引用类型进行特殊处理,因此一般情况下必须由用户提供。
由于该标准不要求简单的可复制性,因此实施者是否竭尽全力提供该保证(这将需要添加额外的专业化)是一个 QoI 问题。