-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
When C++11 is enabled, several algorithms will fail, if GenericValue is neither copyable, nor movable. Cherry-picked from 8005b55.
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)); } |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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)...
* Move() * RawAssign() * SetStringRaw()
* constructor from array is RAPIDJSON_NOEXCEPT * constructor from plain pointer missed an assert
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 either0
or1
), defaulting to0
.There's just the remaining question, whether we want to switch on C++11 mode on travis-ci.org, maybe just for some configurations.