自動產生移動操作
在C 11 中,移動語義的引入引發了關於移動構造函數和移動賦值的情況的問題運算符是自動產生的。
在 C 11 下,移動操作不會像複製建構子和複製賦值那樣自動產生操作員。編譯器僅在滿足某些條件時產生移動語意:
理解這些規則有助於指導利用移動語意的類別的實作。 Howard Hinnant 簡報中的表格提供了自動產生特殊成員的簡潔概述,包括行動操作:
Declaration | Copy Constructor | Copy Assignment Operator | Move Constructor & Move Assignment Operator |
---|---|---|---|
None | Generated | Generated | Not Generated |
Copy Constructor | Not Generated | Generated | Not Generated |
Copy Assignment Operator | Not Generated | Not Generated | Not Generated |
Move Constructor | Not Generated | Not Generated | Not Generated |
Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Destructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Copy Assignment Operator | Not Generated | Not Generated | Not Generated |
Copy Constructor & Move Constructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Copy Assignment Operator & Move Constructor | Not Generated | Not Generated | Not Generated |
Copy Assignment Operator & Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Move Constructor & Destructor | Not Generated | Not Generated | Not Generated |
Move Assignment Operator & Destructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Copy Assignment Operator & Move Constructor | Not Generated | Not Generated | Not Generated |
Copy Constructor & Copy Assignment Operator & Move Assignment Operator | Not Generated | Not Generated | Not Generated |
Copy Constructor & Move Constructor & Move Assignment Operator | Not Generated | Not Generated | Generated |
Copy Assignment Operator & Move Constructor & Move Assignment Operator | Not Generated | Not Generated | Generated |
透過識別這些規則,開發人員可以確保他們的類別正確利用移動語義並實現最佳效率。
以上是C 11 中何時自動產生移動建構函式和移動賦值運算子?的詳細內容。更多資訊請關注PHP中文網其他相關文章!