【问题标题】:error: cannot pass objects of non-trivially-copyable type through `...`错误:无法通过“...”传递非平凡可复制类型的对象
【发布时间】:2016-04-14 13:55:21
【问题描述】:

我有一个类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&amp; point, const geodeticTuple&amp; origin)

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

使用 MSVC2015,这完全正常,但使用 gcc-4.9.3,我收到错误:

错误:无法通过... 传递非平凡可复制类型const geodeticTuple {aka const struct std::tuple&lt;unit, unit, unit&gt;} 的对象

由于 gcc-4.9.3 不支持 is_trivially_xxx 样式类型特征,我无法理解为什么会失败。

平凡类型的元组是不可平凡复制的吗?

【问题讨论】:

  • 为什么要使用旧式 c 可变参数函数而不是可变参数函数模板?
  • 我遇到了麻烦,因为它似乎不喜欢没有参数存在的情况。

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


【解决方案1】:

tuple 的复制/移动赋值运算符需要对引用类型进行特殊处理,因此在一般情况下必须由用户提供。

由于该标准不需要微不足道的可复制性,因此实施者是否花更多时间提供该保证(这将需要添加额外的专业化)是一个 QoI 问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2014-11-19
    • 1970-01-01
    • 2022-08-03
    相关资源
    最近更新 更多