Skip to content

Add Move constructors #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Add Move constructors #264

wants to merge 6 commits into from

Conversation

lanzkron
Copy link
Contributor

Add move constructors to Json::Value and Json::Value::CZString

As requested by issue #223: Json::Value should support move semantics

#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
#endif
#if defined(_MSC_VER) // MSVC
#if _MSC_VER <= 1200 // MSVC 6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't indent preprocessor directives. It's churning the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think it makes the conditions much more readable?
I have no problem to adhere to the coding standards of the project if you think that's better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the indents as written improve the clarity of the file overall.

The usual thing is to keep the # in column 1. This is historical convention.
The next token is indented by 0, 1, or 2 spaces. In this project, it's 0, but you've chosen 8.

The idea is to keep the preprocessor lines visually segregated from the C++ code.
A reader can eyeball column 1 and see a run of #, which is easy.

* Fix indentation
* Allow includer to specify in advance the value for
JSON_HAS_RVALUE_REFERENCES
@cdunn2001 cdunn2001 mentioned this pull request Apr 27, 2015
@cdunn2001
Copy link
Contributor

I rebased onto master (which is better than merging) your code as #267. Move discussion to there, or simply pull that branch and git push -f into your own fork to update this PR.

Don't worry about compatibility. We'll deal with that.

@lanzkron
Copy link
Contributor Author

Rebased by @cdunn2001 in #267, closing this pull request

@lanzkron lanzkron closed this Apr 28, 2015
@cdunn2001
Copy link
Contributor

I have a question: Why do we need to add the move ctor if the default version is provided automatically? ... Oh, I guess the rules for this have evolved. But could we use the new =default notation, instead of writing it ourselves?

@lanzkron
Copy link
Contributor Author

Yeah, if you have a destructor or a copy constructor then the move
constructor will not be generated.

Even if this is not the case from a practical point of view I don't think
all compilers currently generate a default move constructor.

I think we could have done something like:

 Value(Value&&) = default;

But not all current compilers support this either :(

Note: I originally replied to your email which didn't contain the =default suggestion (for some reason) which is why my answer is phrased as it is.

@cdunn2001
Copy link
Contributor

Oh, I sometimes update the comment for clarity. I guess that doesn't send a new e-mail.

Thanks, Motti.

@BillyDonahue
Copy link
Contributor

The implicit move ops don't work for resource-managing classes like Json::Value::CZString.
It would just move (copy) the data members one by one. cstr_ and index_ are just pointer and int, so they'd be copied into the destination, but the source would not be changed and would still think of itself as the owner of its cstr_ data.

@lanzkron
Copy link
Contributor Author

@BillyDonahue good point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants