add and use simplified "internal::Swap"
This avoids the dependency on the <algorithm> header, as suggested by @miloyip in #376.
This commit is contained in:
parent
dd901f498b
commit
0ebe16e169
@ -1810,12 +1810,11 @@ public:
|
||||
\see GenericValue::Swap
|
||||
*/
|
||||
GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT {
|
||||
using std::swap;
|
||||
ValueType::Swap(rhs);
|
||||
stack_.Swap(rhs.stack_);
|
||||
swap(allocator_, rhs.allocator_);
|
||||
swap(ownAllocator_, rhs.ownAllocator_);
|
||||
swap(parseResult_, rhs.parseResult_);
|
||||
internal::Swap(allocator_, rhs.allocator_);
|
||||
internal::Swap(ownAllocator_, rhs.ownAllocator_);
|
||||
internal::Swap(parseResult_, rhs.parseResult_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,8 @@
|
||||
#ifndef RAPIDJSON_INTERNAL_STACK_H_
|
||||
#define RAPIDJSON_INTERNAL_STACK_H_
|
||||
|
||||
#include <algorithm> // std::swap
|
||||
|
||||
#include "../rapidjson.h"
|
||||
#include "swap.h"
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
@ -84,14 +83,12 @@ public:
|
||||
#endif
|
||||
|
||||
void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT {
|
||||
using std::swap;
|
||||
|
||||
swap(allocator_, rhs.allocator_);
|
||||
swap(ownAllocator_, rhs.ownAllocator_);
|
||||
swap(stack_, rhs.stack_);
|
||||
swap(stackTop_, rhs.stackTop_);
|
||||
swap(stackEnd_, rhs.stackEnd_);
|
||||
swap(initialCapacity_, rhs.initialCapacity_);
|
||||
internal::Swap(allocator_, rhs.allocator_);
|
||||
internal::Swap(ownAllocator_, rhs.ownAllocator_);
|
||||
internal::Swap(stack_, rhs.stack_);
|
||||
internal::Swap(stackTop_, rhs.stackTop_);
|
||||
internal::Swap(stackEnd_, rhs.stackEnd_);
|
||||
internal::Swap(initialCapacity_, rhs.initialCapacity_);
|
||||
}
|
||||
|
||||
void Clear() { stackTop_ = stack_; }
|
||||
|
37
include/rapidjson/internal/swap.h
Normal file
37
include/rapidjson/internal/swap.h
Normal file
@ -0,0 +1,37 @@
|
||||
// Tencent is pleased to support the open source community by making RapidJSON available.
|
||||
//
|
||||
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
|
||||
//
|
||||
// Licensed under the MIT License (the "License"); you may not use this file except
|
||||
// in compliance with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://opensource.org/licenses/MIT
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software distributed
|
||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations under the License.
|
||||
|
||||
#ifndef RAPIDJSON_INTERNAL_SWAP_H_
|
||||
#define RAPIDJSON_INTERNAL_SWAP_H_
|
||||
|
||||
#include "../rapidjson.h"
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
//! Custom swap() to avoid dependency on C++ <algorith> header
|
||||
/*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only.
|
||||
\note This has the same semantics as std::swap().
|
||||
*/
|
||||
template <typename T>
|
||||
inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT {
|
||||
T tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#endif // RAPIDJSON_INTERNAL_SWAP_H_
|
Loading…
x
Reference in New Issue
Block a user