- 论坛徽章:
- 0
|
本帖最后由 Frahm 于 2013-04-17 15:46 编辑
我很疑惑,std::is_move_constructible<T>::value的值总是true,比如我声明一个空类,它也是true, 所以我就认为编译器自动生成了对应的move ctor,然而经过测试,我发现不然。
- struct foo {
- int* ptr;
- };
- int main() {
- {
- std::cout << std::is_move_constructible<foo>::value << '\n';
- foo f;
- f.ptr = (int*)12;
- foo f2(std::move(f));
- std::cout << f.ptr << ' ' << f2.ptr << '\n';
- }
- return 0;
- }
复制代码 输出的f.ptr和f2.ptr是一样的,我以为默认的行为会把f.ptr赋值为nullptr, 不然的话不是很危险吗。。。
我感觉编译器根本就没有自动生成move ctor。
也就是说std::is_move_constructible这个trait 没有用?
有没有能确切表示可以被move 构造的trait呢? |
|