- 論壇徽章:
- 0
|
本帖最后由 Frahm 于 2013-04-17 15:46 編輯
我很疑惑,std::is_move_constructible<T>::value的值總是true,比如我聲明一個空類,它也是true, 所以我就認為編譯器自動生成了對應(yīng)的move ctor,然而經(jīng)過測試,我發(fā)現(xiàn)不然。
- 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ù)制代碼 輸出的f.ptr和f2.ptr是一樣的,我以為默認的行為會把f.ptr賦值為nullptr, 不然的話不是很危險嗎。。。
我感覺編譯器根本就沒有自動生成move ctor。
也就是說std::is_move_constructible這個trait 沒有用?
有沒有能確切表示可以被move 構(gòu)造的trait呢? |
|