-
Firstly, let me say thank you for this awesome library @nlohmann ! OK. Question: When utilizing the copy (not move) assignment operator, what copy technique is employed? I can think of 3 possibilities:
Any of these works for me, but I don't know which are at play! Thank you Related: When I try to use the copy constructor in an initializer list, it tosses me into an array rabbit hole regardless of the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The single assignment operator uses the by-value-parameter-and-swap idiom. It takes the RHS 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 |
Beta Was this translation helpful? Give feedback.
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