1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Implementation of the swap utility.
11///
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_SWAP_H
14#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_SWAP_H
15
16#include "hdr/types/size_t.h"
17#include "src/__support/CPP/utility/move.h"
18#include "src/__support/macros/attributes.h"
19#include "src/__support/macros/config.h"
20
21namespace LIBC_NAMESPACE_DECL {
22namespace cpp {
23
24template <class T> LIBC_INLINE constexpr void swap(T &a, T &b) {
25 T temp = cpp::move(a);
26 a = cpp::move(b);
27 b = cpp::move(temp);
28}
29
30template <class T, size_t N>
31LIBC_INLINE constexpr void swap(T (&a)[N], T (&b)[N]) {
32 for (size_t i = 0; i < N; ++i)
33 swap(a[i], b[i]);
34}
35
36} // namespace cpp
37} // namespace LIBC_NAMESPACE_DECL
38
39#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_SWAP_H
40