2016-04-14 25 views
0

我有一個類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)或使用MSVC2015

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

,這工作完全正常,但用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風格類型特徵,我很難理解爲什麼這是失敗的。

是一個不平凡的類型的元組不平凡複製?

+0

爲什麼你使用舊式c vararg函數而不是可變參數函數模板? –

+0

我遇到了麻煩,因爲當沒有參數存在時它似乎不喜歡。 –

回答

1

tuple的複製/移動賦值操作符需要對引用類型進行特殊處理,因此它們在一般情況下必須由用戶提供。

由於該標準不需要繁瑣的可複製性,實施者是否需要額外提供該擔保(這將需要添加額外的專業化),這是一個QoI問題。

相關問題