问题:
What is this idiom and when should it be used? 这个习语是什么,什么时候应该使用? Which problems does it solve? 它可以解决哪些问题? Does the idiom change when C++11 is used? 使用C ++ 11时,习惯用法会改变吗?
Although it's been mentioned in many places, we didn't have any singular "what is it" question and answer, so here it is. 尽管在很多地方都提到过它,但是我们没有任何奇异的“这是什么”的问题和答案,所以就在这里。 Here is a partial list of places where it was previously mentioned: 这是先前提到的地方的部分列表:
- What are your favorite C++ Coding Style idioms: Copy-swap 您最喜欢的C ++编码样式惯用法是什么:复制交换
- Copy constructor and = operator overload in C++: is a common function possible? 在C ++中复制构造函数和=运算符重载:是否可能使用通用函数?
- What is copy elision and how it optimizes copy-and-swap idiom 什么是复制省略及其如何优化复制和交换习惯
- C++: dynamically allocating an array of objects? C ++:动态分配对象数组?
解决方案:
参考一: https://stackoom.com/question/Dl9r/什么是复制和交换习语参考二: https://oldbug.net/q/Dl9r/What-is-the-copy-and-swap-idiom
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/4467641