error: cannot pass objects of non-trivially-copyable type through `…`

陌路散爱 提交于 2019-12-12 01:36:37

问题


I have a class unit, which has the properties

std::is_trivial<unit>::value; // true
std::is_trivially_copyable<unit>::value; // true (on compilers which have this trait)

I'd like to pass are vectors of unit as a tuple, e.g.

using geodeticTuple = std::tuple<unit, unit, unit>;

I need these vectors to be passable into conversion functions who use different types of arguments, e.g.

someOtherType convert(const geodeticTuple& point, const geodeticTuple& origin) or

someOtherType convert(const geodeticTuple& point, ...)

using MSVC2015, this works totally fine, but with gcc-4.9.3, I'm getting the error:

error: cannot pass objects of non-trivially-copyable type const geodeticTuple {aka const struct std::tuple<unit, unit, unit>} through ...

and since gcc-4.9.3 doesn't support the is_trivially_xxx style type-traits, I'm having trouble understanding why this is failing.

Is a tuple of trivial types not trivially copyable?


回答1:


tuple's copy/move assignment operators require special handling for reference types, so they must be user-provided in the general case.

Since the standard doesn't require trivial copyability, it's a QoI issue whether the implementers go to the extra length of providing that guarantee (which would require adding additional specializations).



来源:https://stackoverflow.com/questions/36625317/error-cannot-pass-objects-of-non-trivially-copyable-type-through

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!