Skip to content
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

Initial C++11 move support #128

Merged
merged 12 commits into from
Sep 3, 2014
Merged

Initial C++11 move support #128

merged 12 commits into from
Sep 3, 2014

Conversation

pah
Copy link
Contributor

@pah pah commented Aug 31, 2014

As discussed in 8005b55 and #123, C++11 move support based on rvalue-references would be useful.

This pull-request provides an initial implementation, although restricted to GenericValue only. I had a quick look and adding move support to the other classes might not be worth the effort for now.

I looked up minimum versions and detection mechanisms for Clang, GCC and MSVC. Users can set RAPIDJSON_HAS_CXX_* to override the automatic detection of the required features.

On a side path, I switched RAPIDJSON_HAS_STDSTRING to a symbol that is always available (and either 0 or 1), defaulting to 0.

There's just the remaining question, whether we want to switch on C++11 mode on travis-ci.org, maybe just for some configurations.

pah added 10 commits August 31, 2014 12:25
When C++11 is enabled, several algorithms will fail, if GenericValue is
neither copyable, nor movable.

Cherry-picked from 8005b55.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Directly allows temporary GenericValues as parameters:
  v.AddMember("foo", Value(s.c_str(),alloc), alloc);
Added basic detection of `noexcept` support for some compilers, added
corresponding RAPIDJSON_NOEXCEPT annotations to
 * non-allocating constructors
 * (move) assignment
 * Swap

//! Constructor for constant string (i.e. do not make a copy of string)
GenericValue(const Ch* s, SizeType length) : data_(), flags_() { SetStringRaw(StringRef(s, length)); }
GenericValue(const Ch* s, SizeType length) RAPIDJSON_NOEXCEPT : data_(), flags_() { SetStringRaw(StringRef(s, length)); }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, this is not noexcept, since it will/can involve a memory allocation...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it won't allocate memory. See SetStringRaw (and comment before the constructor).

Copy link
Contributor

Choose a reason for hiding this comment

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

I mixed that with the version taking the allocator (since I only used that for now)...

pah added 2 commits August 31, 2014 22:00
 * Move()
 * RawAssign()
 * SetStringRaw()
 * constructor from array is RAPIDJSON_NOEXCEPT
 * constructor from plain pointer missed an assert
miloyip added a commit that referenced this pull request Sep 3, 2014
@miloyip miloyip merged commit bc9d786 into Tencent:master Sep 3, 2014
@pah pah deleted the feature/cxx11-move branch September 3, 2014 05:51
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.

None yet

4 participants