VCCC  2024.05
VisualCamp Common C++ library
swap_ranges.hpp
Go to the documentation of this file.
1 //
2 // Created by cosge on 2023-12-03.
3 //
4 
5 #ifndef VCCC_ALGORITHM_RANGES_SWAP_RANGES_HPP
6 #define VCCC_ALGORITHM_RANGES_SWAP_RANGES_HPP
7 
8 #include <type_traits>
9 #include <utility>
10 
18 
19 namespace vccc {
20 namespace ranges {
21 
24 
25 template< class I1, class I2 >
27 
28 namespace detail {
29 
30 struct swap_ranges_niebloid {
31  template<typename I1, typename S1, typename I2, typename S2, std::enable_if_t<conjunction<
35  >::value, int> = 0>
36  constexpr swap_ranges_result<I1, I2> operator()(I1 first1, S1 last1, I2 first2, S2 last2) const {
37  for (; !(first1 == last1 || first2 == last2); ++first1, ++first2)
38  ranges::iter_swap(first1, first2);
39  return {std::move(first1), std::move(first2)};
40  }
41 
42  template<typename R1, typename R2, std::enable_if_t<conjunction<
46  >::value, int> = 0>
47  constexpr void operator()(R1&& r1, R2&& r2) const {
48  return (*this)(ranges::begin(r1), ranges::end(r1), ranges::begin(r2), ranges::end(r2));
49  }
50 };
51 
52 } // namespace detail
53 
54 VCCC_INLINE_OR_STATIC constexpr detail::swap_ranges_niebloid swap_ranges{};
55 
57 
58 } // namespace ranges
59 } // namespace vccc
60 
61 #endif // VCCC_ALGORITHM_RANGES_SWAP_RANGES_HPP
constexpr VCCC_INLINE_OR_STATIC detail::swap_ranges_niebloid swap_ranges
Definition: swap_ranges.hpp:54
constexpr VCCC_INLINE_OR_STATIC detail_iter_swap::iter_swap_niebloid iter_swap
Definition: iter_swap.hpp:90
typename ranges::iterator< T >::type iterator_t
Definition: iterator_t.hpp:32
constexpr VCCC_INLINE_OR_STATIC detail::begin_niebloid begin
returns an iterator to the beginning of a range
Definition: begin.hpp:116
constexpr VCCC_INLINE_OR_STATIC detail::end_niebloid end
returns a sentinel indicating the end of a range
Definition: end.hpp:120
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: conjunction.hpp:22
Definition: indirectly_swappable.hpp:46
specifies that a type is an input iterator, that is, its referenced values can be read and it can be ...
Definition: input_iterator.hpp:55
Definition: in_in_result.hpp:22
specifies a range whose iterator type satisfies input_iterator
Definition: input_range.hpp:46
Definition: sentinel_for.hpp:24