问题
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