建有this online compiler,下面的代码:为什么不能std :: tuple <int>可以复制?
#include <iostream>
#include <type_traits>
#include <tuple>
int main() {
std::cout << std::is_trivially_copyable<std::tuple<int>>::value << std::endl;
std::cout << std::is_trivially_copyable<std::pair<int, int>>::value << std::endl;
std::cout << std::is_trivial<std::tuple<int>>::value << std::endl;
std::cout << std::is_trivial<std::pair<int, int>>::value << std::endl;
return 0;
}
输出:
0
0
0
0
我得到与Visual Studio相同的结果,2015年
为什么是这样呢?是否有POD类型的std::tuple
的有效理由,更不用说简单的std::pair
,不能简单地复制?我认为他们的实现提供了一些自定义赋值操作符,但它们与编译器生成的默认版本有什么不同?
http://stackoverflow.com/questions/36625317/error-cannot-pass-objects-of-non-trivially-copyable-type-through意味着该标准不需要它,所以实现不打扰 – happydave