Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:32

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___ITERATOR_ITER_SWAP_H
0011 #define _LIBCPP___CXX03___ITERATOR_ITER_SWAP_H
0012 
0013 #include <__cxx03/__concepts/class_or_enum.h>
0014 #include <__cxx03/__concepts/swappable.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__iterator/concepts.h>
0017 #include <__cxx03/__iterator/iter_move.h>
0018 #include <__cxx03/__iterator/iterator_traits.h>
0019 #include <__cxx03/__iterator/readable_traits.h>
0020 #include <__cxx03/__type_traits/remove_cvref.h>
0021 #include <__cxx03/__utility/declval.h>
0022 #include <__cxx03/__utility/forward.h>
0023 #include <__cxx03/__utility/move.h>
0024 
0025 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0026 #  pragma GCC system_header
0027 #endif
0028 
0029 _LIBCPP_PUSH_MACROS
0030 #include <__cxx03/__undef_macros>
0031 
0032 _LIBCPP_BEGIN_NAMESPACE_STD
0033 
0034 #if _LIBCPP_STD_VER >= 20
0035 
0036 // [iter.cust.swap]
0037 
0038 namespace ranges {
0039 namespace __iter_swap {
0040 template <class _I1, class _I2>
0041 void iter_swap(_I1, _I2) = delete;
0042 
0043 template <class _T1, class _T2>
0044 concept __unqualified_iter_swap =
0045     (__class_or_enum<remove_cvref_t<_T1>> || __class_or_enum<remove_cvref_t<_T2>>) && requires(_T1&& __x, _T2&& __y) {
0046       // NOLINTNEXTLINE(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap
0047       iter_swap(std::forward<_T1>(__x), std::forward<_T2>(__y));
0048     };
0049 
0050 template <class _T1, class _T2>
0051 concept __readable_swappable =
0052     indirectly_readable<_T1> && indirectly_readable<_T2> &&
0053     swappable_with<iter_reference_t<_T1>, iter_reference_t<_T2>>;
0054 
0055 struct __fn {
0056   // NOLINTBEGIN(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap
0057   template <class _T1, class _T2>
0058     requires __unqualified_iter_swap<_T1, _T2>
0059   _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_T1&& __x, _T2&& __y) const
0060       noexcept(noexcept(iter_swap(std::forward<_T1>(__x), std::forward<_T2>(__y)))) {
0061     (void)iter_swap(std::forward<_T1>(__x), std::forward<_T2>(__y));
0062   }
0063   // NOLINTEND(libcpp-robust-against-adl)
0064 
0065   template <class _T1, class _T2>
0066     requires(!__unqualified_iter_swap<_T1, _T2>) && __readable_swappable<_T1, _T2>
0067   _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_T1&& __x, _T2&& __y) const
0068       noexcept(noexcept(ranges::swap(*std::forward<_T1>(__x), *std::forward<_T2>(__y)))) {
0069     ranges::swap(*std::forward<_T1>(__x), *std::forward<_T2>(__y));
0070   }
0071 
0072   template <class _T1, class _T2>
0073     requires(!__unqualified_iter_swap<_T1, _T2> &&   //
0074              !__readable_swappable<_T1, _T2>) &&     //
0075             indirectly_movable_storable<_T1, _T2> && //
0076             indirectly_movable_storable<_T2, _T1>
0077   _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_T1&& __x, _T2&& __y) const
0078       noexcept(noexcept(iter_value_t<_T2>(ranges::iter_move(__y))) && //
0079                noexcept(*__y = ranges::iter_move(__x)) &&             //
0080                noexcept(*std::forward<_T1>(__x) = std::declval<iter_value_t<_T2>>())) {
0081     iter_value_t<_T2> __old(ranges::iter_move(__y));
0082     *__y                    = ranges::iter_move(__x);
0083     *std::forward<_T1>(__x) = std::move(__old);
0084   }
0085 };
0086 } // namespace __iter_swap
0087 
0088 inline namespace __cpo {
0089 inline constexpr auto iter_swap = __iter_swap::__fn{};
0090 } // namespace __cpo
0091 } // namespace ranges
0092 
0093 template <class _I1, class _I2 = _I1>
0094 concept indirectly_swappable =
0095     indirectly_readable<_I1> && indirectly_readable<_I2> && requires(const _I1 __i1, const _I2 __i2) {
0096       ranges::iter_swap(__i1, __i1);
0097       ranges::iter_swap(__i2, __i2);
0098       ranges::iter_swap(__i1, __i2);
0099       ranges::iter_swap(__i2, __i1);
0100     };
0101 
0102 #endif // _LIBCPP_STD_VER >= 20
0103 
0104 _LIBCPP_END_NAMESPACE_STD
0105 
0106 _LIBCPP_POP_MACROS
0107 
0108 #endif // _LIBCPP___CXX03___ITERATOR_ITER_SWAP_H