VCCC  2024.05
VisualCamp Common C++ library
move_sentinel.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 1/26/24.
3 //
4 
5 #ifndef VCCC_ITERATOR_MOVE_SENTINEL_HPP
6 #define VCCC_ITERATOR_MOVE_SENTINEL_HPP
7 
8 #include <iterator>
9 #include <type_traits>
10 #include <utility>
11 
17 
18 namespace vccc {
19 
22 
23 template<typename S>
25  public:
26  static_assert(semiregular<S>::value, "Constraints not satisfied");
27 
28  constexpr move_sentinel() = default;
29 
30  constexpr explicit move_sentinel(S x)
31  : last_(x) {}
32 
34  constexpr move_sentinel(const move_sentinel<S2>& other)
35  : last_(other.last_) {}
36 
38  constexpr move_sentinel& operator=(const move_sentinel<S2>& other) {
39  last_ = other.last_;
40  }
41 
42  constexpr S base() const {
43  return last_;
44  }
45 
47  friend constexpr bool operator==(const std::move_iterator<Iter>& i, const move_sentinel& s) {
48  return i.base() == s.last_;
49  }
50 
52  friend constexpr bool operator!=(const std::move_iterator<Iter>& i, const move_sentinel& s) {
53  return !(i == s);
54  }
55 
57  friend constexpr bool operator==(const move_sentinel& s, const std::move_iterator<Iter>& i) {
58  return i.base() == s.last_;
59  }
60 
62  friend constexpr bool operator!=(const move_sentinel& s, const std::move_iterator<Iter>& i) {
63  return !(i == s);
64  }
65 
67  friend constexpr iter_difference_t<Iter> operator-(const move_sentinel& s, const std::move_iterator<Iter>& i) {
68  return s.last_ - i.base();
69  }
70 
72  friend constexpr iter_difference_t<Iter> operator-(const std::move_iterator<Iter>& i, const move_sentinel& s) {
73  return i.base() - s.last_;
74  }
75 
76  private:
77  S last_;
78 };
79 
81 
82 } // namespace vccc
83 
84 #endif // VCCC_ITERATOR_MOVE_SENTINEL_HPP
Definition: move_sentinel.hpp:24
constexpr move_sentinel(const move_sentinel< S2 > &other)
Definition: move_sentinel.hpp:34
constexpr friend iter_difference_t< Iter > operator-(const std::move_iterator< Iter > &i, const move_sentinel &s)
Definition: move_sentinel.hpp:72
constexpr friend iter_difference_t< Iter > operator-(const move_sentinel &s, const std::move_iterator< Iter > &i)
Definition: move_sentinel.hpp:67
constexpr friend bool operator==(const move_sentinel &s, const std::move_iterator< Iter > &i)
Definition: move_sentinel.hpp:57
constexpr move_sentinel()=default
constexpr friend bool operator!=(const move_sentinel &s, const std::move_iterator< Iter > &i)
Definition: move_sentinel.hpp:62
constexpr move_sentinel & operator=(const move_sentinel< S2 > &other)
Definition: move_sentinel.hpp:38
constexpr move_sentinel(S x)
Definition: move_sentinel.hpp:30
constexpr friend bool operator==(const std::move_iterator< Iter > &i, const move_sentinel &s)
Definition: move_sentinel.hpp:47
constexpr S base() const
Definition: move_sentinel.hpp:42
constexpr friend bool operator!=(const std::move_iterator< Iter > &i, const move_sentinel &s)
Definition: move_sentinel.hpp:52
typename iter_difference< T >::type iter_difference_t
Computes the difference type of T
Definition: iter_difference_t.hpp:49
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
specifies that an object of a type can be copied, moved, swapped, and default constructed
Definition: semiregular.hpp:31