c++ - 错误 : cannot pass objects of non-trivially-copyable type through `...`

标签 c++ c++11 tuples typetraits stdtuple

我有一个类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/

相关文章:

python - 如何为元组的每个元素添加一个数字?

python - 如何将元组转换为元组列表?

c++ - 按照运行时定义的顺序遍历 C++ 元组

windows - Windows 上的线程创建速度慢

c# - 如何解构可空元组?

c++ - std::vector::begin() - 1 是否未定义?

c++ - 将 CUDA printf 重定向到 C++ 流

c++ - 如何检查 std::string 是否确实是整数?

c++ - 垃圾收集事件的 LuaPlus 和 c++ 回调

C++ Lambdas : capture list vs. 参数列表