Quantcast
Channel: What is the copy-and-swap idiom? - Stack Overflow
Browsing all 6 articles
Browse latest View live

Answer by Kerrek SB for What is the copy-and-swap idiom?

I would like to add a word of warning when you are dealing with C++11-style allocator-aware containers. Swapping and assignment have subtly different semantics. For concreteness, let us consider a...

View Article



Answer by Tony Delroy for What is the copy-and-swap idiom?

There are some good answers already. I'll focus mainly on what I think they lack - an explanation of the "cons" with the copy-and-swap idiom.... What is the copy-and-swap idiom? A way of implementing...

View Article

Image may be NSFW.
Clik here to view.

Answer by Oleksiy for What is the copy-and-swap idiom?

This answer is more like an addition and a slight modification to the answers above. In some versions of Visual Studio (and possibly other compilers) there is a bug that is really annoying and doesn't...

View Article

Answer by sbi for What is the copy-and-swap idiom?

Assignment, at its heart, is two steps: tearing down the object's old state and building its new state as a copy of some other object's state. Basically, that's what the destructor and the copy...

View Article

Answer by GManNickG for What is the copy-and-swap idiom?

Overview Why do we need the copy-and-swap idiom? Any class that manages a resource (a wrapper, like a smart pointer) needs to implement The Big Three. While the goals and implementation of the...

View Article


What is the copy-and-swap idiom?

What is this idiom and when should it be used? Which problems does it solve? Does the idiom change when C++11 is used? Although it's been mentioned in many places, we didn't have any singular "what is...

View Article
Browsing all 6 articles
Browse latest View live




Latest Images