Path: blob/main/contrib/llvm-project/libcxx/include/__iterator/iter_swap.h
35233 views
// -*- C++ -*-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-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___ITERATOR_ITER_SWAP_H10#define _LIBCPP___ITERATOR_ITER_SWAP_H1112#include <__concepts/class_or_enum.h>13#include <__concepts/swappable.h>14#include <__config>15#include <__iterator/concepts.h>16#include <__iterator/iter_move.h>17#include <__iterator/iterator_traits.h>18#include <__iterator/readable_traits.h>19#include <__type_traits/remove_cvref.h>20#include <__utility/declval.h>21#include <__utility/forward.h>22#include <__utility/move.h>2324#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)25# pragma GCC system_header26#endif2728_LIBCPP_PUSH_MACROS29#include <__undef_macros>3031_LIBCPP_BEGIN_NAMESPACE_STD3233#if _LIBCPP_STD_VER >= 203435// [iter.cust.swap]3637namespace ranges {38namespace __iter_swap {39template <class _I1, class _I2>40void iter_swap(_I1, _I2) = delete;4142template <class _T1, class _T2>43concept __unqualified_iter_swap =44(__class_or_enum<remove_cvref_t<_T1>> || __class_or_enum<remove_cvref_t<_T2>>) && requires(_T1&& __x, _T2&& __y) {45// NOLINTNEXTLINE(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap46iter_swap(std::forward<_T1>(__x), std::forward<_T2>(__y));47};4849template <class _T1, class _T2>50concept __readable_swappable =51indirectly_readable<_T1> && indirectly_readable<_T2> &&52swappable_with<iter_reference_t<_T1>, iter_reference_t<_T2>>;5354struct __fn {55// NOLINTBEGIN(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap56template <class _T1, class _T2>57requires __unqualified_iter_swap<_T1, _T2>58_LIBCPP_HIDE_FROM_ABI constexpr void operator()(_T1&& __x, _T2&& __y) const59noexcept(noexcept(iter_swap(std::forward<_T1>(__x), std::forward<_T2>(__y)))) {60(void)iter_swap(std::forward<_T1>(__x), std::forward<_T2>(__y));61}62// NOLINTEND(libcpp-robust-against-adl)6364template <class _T1, class _T2>65requires(!__unqualified_iter_swap<_T1, _T2>) && __readable_swappable<_T1, _T2>66_LIBCPP_HIDE_FROM_ABI constexpr void operator()(_T1&& __x, _T2&& __y) const67noexcept(noexcept(ranges::swap(*std::forward<_T1>(__x), *std::forward<_T2>(__y)))) {68ranges::swap(*std::forward<_T1>(__x), *std::forward<_T2>(__y));69}7071template <class _T1, class _T2>72requires(!__unqualified_iter_swap<_T1, _T2> && //73!__readable_swappable<_T1, _T2>) && //74indirectly_movable_storable<_T1, _T2> && //75indirectly_movable_storable<_T2, _T1>76_LIBCPP_HIDE_FROM_ABI constexpr void operator()(_T1&& __x, _T2&& __y) const77noexcept(noexcept(iter_value_t<_T2>(ranges::iter_move(__y))) && //78noexcept(*__y = ranges::iter_move(__x)) && //79noexcept(*std::forward<_T1>(__x) = std::declval<iter_value_t<_T2>>())) {80iter_value_t<_T2> __old(ranges::iter_move(__y));81*__y = ranges::iter_move(__x);82*std::forward<_T1>(__x) = std::move(__old);83}84};85} // namespace __iter_swap8687inline namespace __cpo {88inline constexpr auto iter_swap = __iter_swap::__fn{};89} // namespace __cpo90} // namespace ranges9192template <class _I1, class _I2 = _I1>93concept indirectly_swappable =94indirectly_readable<_I1> && indirectly_readable<_I2> && requires(const _I1 __i1, const _I2 __i2) {95ranges::iter_swap(__i1, __i1);96ranges::iter_swap(__i2, __i2);97ranges::iter_swap(__i1, __i2);98ranges::iter_swap(__i2, __i1);99};100101#endif // _LIBCPP_STD_VER >= 20102103_LIBCPP_END_NAMESPACE_STD104105_LIBCPP_POP_MACROS106107#endif // _LIBCPP___ITERATOR_ITER_SWAP_H108109110