VCCC  2024.05
VisualCamp Common C++ library
iter_swap.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 2023/12/27.
3 //
4 
5 #ifndef VCCC_ITERATOR_ITER_SWAP_HPP
6 #define VCCC_ITERATOR_ITER_SWAP_HPP
7 
8 #include <type_traits>
9 #include <utility>
10 
24 
25 namespace vccc {
26 namespace ranges {
27 namespace detail_iter_swap {
28 
29 template<typename T, typename U>
30 void iter_swap(T, U) = delete;
31 
32 template<typename T, typename U>
33 constexpr auto test_iter_swap(int) -> decltype(iter_swap(std::declval<T>(), std::declval<U>()), std::true_type{});
34 
35 template<typename T, typename U>
36 constexpr auto test_iter_swap(...) -> std::false_type;
37 
38 template<typename T, typename U, bool = disjunction<
41  >::value>
42 struct unqual_iter_swap : decltype(test_iter_swap<T, U>(0)) {};
43 
44 template<typename T, typename U>
45 struct unqual_iter_swap<T, U, true> : decltype(test_iter_swap<T, U>(0)) {};
46 
47 template<typename I1, typename I2, bool = conjunction<indirectly_readable<I1>, indirectly_readable<I2>>::value /* false */>
48 struct read_iter_swap : std::false_type{};
49 template<typename I1, typename I2>
50 struct read_iter_swap<I1, I2, false> : swappable_with<iter_reference_t<I1>, iter_reference_t<I2>> {};
51 
54  constexpr void operator()(I1&& i1, I2&& i2) const
55  noexcept(noexcept(iter_swap(std::forward<I1>(i1), std::forward<I2>(i2))))
56  {
57  (void)iter_swap(std::forward<I1>(i1), std::forward<I2>(i2));
58  }
59 
60  template<typename I1, typename I2, std::enable_if_t<conjunction<
63  >::value, int> = 0>
64  constexpr void operator()(I1&& i1, I2&& i2) const
65  noexcept(noexcept(ranges::swap(*i1, *i2)))
66  {
67  ranges::swap(*std::forward<I1>(i1), *std::forward<I2>(i2));
68  }
69 
70  template<typename I1, typename I2, std::enable_if_t<conjunction<
75  >::value, int> = 0>
76  constexpr void operator()(I1&& i1, I2&& i2) const
77  noexcept(noexcept( *i1 = vccc::detail::iter_exchange_move(std::forward<I2>(i2), std::forward<I1>(i1)) ))
78  {
79  (void)(*i1 = vccc::detail::iter_exchange_move(std::forward<I2>(i2), std::forward<I1>(i1)));
80  }
81 };
82 
83 } // namespace detail_iter_swap
84 
85 namespace niebloid {
86 
89 
91 
93 
94 } // namespace niebloid
95 using namespace niebloid;
96 
97 } // namespace ranges
98 } // namespace vccc
99 
100 #endif // VCCC_ITERATOR_ITER_SWAP_HPP
constexpr VCCC_INLINE_OR_STATIC detail_ranges_swap::swap_niebloid swap
swaps the values of two objects
Definition: swap.hpp:99
constexpr VCCC_INLINE_OR_STATIC detail_iter_swap::iter_swap_niebloid iter_swap
Definition: iter_swap.hpp:90
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
constexpr auto test_iter_swap(int) -> decltype(iter_swap(std::declval< T >(), std::declval< U >()), std::true_type{})
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: conjunction.hpp:22
Definition: disjunction.hpp:22
specifies that values may be moved from an indirectly_readable type to an indirectly_writable type an...
Definition: indirectly_movable_storable.hpp:50
Definition: is_class_or_enum.hpp:20
Definition: negation.hpp:23
constexpr void operator()(I1 &&i1, I2 &&i2) const noexcept(noexcept(ranges::swap(*i1, *i2)))
Definition: iter_swap.hpp:64
constexpr void operator()(I1 &&i1, I2 &&i2) const noexcept(noexcept(iter_swap(std::forward< I1 >(i1), std::forward< I2 >(i2))))
Definition: iter_swap.hpp:54
constexpr void operator()(I1 &&i1, I2 &&i2) const noexcept(noexcept(*i1=vccc::detail::iter_exchange_move(std::forward< I2 >(i2), std::forward< I1 >(i1))))
Definition: iter_swap.hpp:76
specifies that a type can be swapped or that two types can be swapped with each other
Definition: swappable_with.hpp:51