- The copy-and-swap idiom is used in creating the copy assignment operator and prevents us from replicating code in the copy constructor and destructor. It's about assigning one object B to another A and destructing the memory previously held by the name A. As constructors should have strong safety guarantees, it should first allocate the memory needed and then clear the old copy, to ensure that it doesn't throw some bad alloc after it has destructed the object. It also takes a copy-by-val RHS, which can be destructed automatically after the function and swaps the contents of the RHS into 'this'. This serves all purposes and is simply copy first, followed by swap.
- RVO and copy-elision (when passing arguments into functions) can let compilers do some fancy optimizations, while keeping things like constness of names and smaller code size. Pass-by-val can be quite fast if the compiler does optimize certain things.
Last active
November 28, 2015 16:52
-
-
Save foxish/705627d8d4a2adc3c425 to your computer and use it in GitHub Desktop.
2015Nov28
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment