错误:无法通过`...`传递非平凡可复制类型的对象

时间:2016-04-14 13:55:21

标签: 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的向量作为元组传递,例如。

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,我收到了错误:

  

错误:无法通过const geodeticTuple {aka const struct std::tuple<unit, unit, unit>}

传递非平凡可复制类型...的对象

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

琐碎类型的元组是不是可以轻易复制的?

1 个答案:

答案 0 :(得分:1)

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

由于该标准不需要简单的可复制性,因此实施者是否需要额外的长度来提供该保证(这需要添加额外的专业化),这是一个QoI问题。

相关问题