Skip to content

Memory management during copy #4257

Answered by gregmarr
malachib asked this question in Q&A
Jan 3, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

The single assignment operator uses the by-value-parameter-and-swap idiom. It takes the RHS json object by value, and then swaps contents with that by-value parameter.

If the assignment operator is passed an rvalue, then the by-value parameter is constructed using the move constructor, otherwise it's constructed using the copy constructor. The copy constructor does a deep copy. The move constructor just steals the value.

The initializer list constructor can be a bit weird at times, and the behavior is actually different depending on which compiler you are using. #2311

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@malachib
Comment options

@gregmarr
Comment options

@malachib
Comment options

Answer selected by malachib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants