diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 5eeef9c..3496c2b 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -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; } diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 198c866..0d4a7f7 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -15,9 +15,8 @@ #ifndef RAPIDJSON_INTERNAL_STACK_H_ #define RAPIDJSON_INTERNAL_STACK_H_ -#include // 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_; } diff --git a/include/rapidjson/internal/swap.h b/include/rapidjson/internal/swap.h new file mode 100644 index 0000000..41e7e20 --- /dev/null +++ b/include/rapidjson/internal/swap.h @@ -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++ 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 +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_