1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___OPTIONAL_SWAP_H
11#define _LIBCPP___OPTIONAL_SWAP_H
12
13#include <__config>
14#include <__type_traits/enable_if.h>
15#include <__type_traits/is_constructible.h>
16#include <__type_traits/is_reference.h>
17#include <__type_traits/is_swappable.h>
18
19#include <__fwd/optional.h>
20
21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22# pragma GCC system_header
23#endif
24
25#if _LIBCPP_STD_VER >= 17
26
27_LIBCPP_BEGIN_NAMESPACE_STD
28
29template <class _Tp,
30 enable_if_t<(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>)
31# if _LIBCPP_STD_VER >= 26
32 || is_reference_v<_Tp>
33# endif
34 ,
35 int> = 0>
36inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
37swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) {
38 __x.swap(__y);
39}
40
41_LIBCPP_END_NAMESPACE_STD
42
43#endif // _LIBCPP_STD_VER >= 17
44
45#endif // _LIBCPP___OPTIONAL_SWAP_H
46