swap.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Tencent is pleased to support the open source community by making RapidJSON
  2. // available.
  3. //
  4. // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
  5. // rights reserved.
  6. //
  7. // Licensed under the MIT License (the "License"); you may not use this file
  8. // except in compliance with the License. You may obtain a copy of the License
  9. // at
  10. //
  11. // http://opensource.org/licenses/MIT
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. // License for the specific language governing permissions and limitations under
  17. // the License.
  18. #ifndef RAPIDJSON_INTERNAL_SWAP_H_
  19. #define RAPIDJSON_INTERNAL_SWAP_H_
  20. #include "../rapidjson.h"
  21. #if defined(__clang__)
  22. RAPIDJSON_DIAG_PUSH
  23. RAPIDJSON_DIAG_OFF(c++ 98 - compat)
  24. #endif
  25. RAPIDJSON_NAMESPACE_BEGIN
  26. namespace internal {
  27. //! Custom swap() to avoid dependency on C++ <algorithm> header
  28. /*! \tparam T Type of the arguments to swap, should be instantiated with
  29. primitive C++ types only. \note This has the same semantics as std::swap().
  30. */
  31. template <typename T>
  32. inline void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT {
  33. T tmp = a;
  34. a = b;
  35. b = tmp;
  36. }
  37. } // namespace internal
  38. RAPIDJSON_NAMESPACE_END
  39. #if defined(__clang__)
  40. RAPIDJSON_DIAG_POP
  41. #endif
  42. #endif // RAPIDJSON_INTERNAL_SWAP_H_