EnTT  3.9.0
range.hpp
1 #ifndef ENTT_META_RANGE_HPP
2 #define ENTT_META_RANGE_HPP
3 
4 #include <cstddef>
5 #include <iterator>
6 #include "../core/iterator.hpp"
7 
8 namespace entt {
9 
15 namespace internal {
16 
17 template<typename Type, typename Node>
18 struct meta_range_iterator {
19  using difference_type = std::ptrdiff_t;
20  using value_type = Type;
21  using pointer = input_iterator_pointer<value_type>;
22  using reference = value_type;
23  using iterator_category = std::input_iterator_tag;
24  using node_type = Node;
25 
26  meta_range_iterator() ENTT_NOEXCEPT = default;
27 
28  meta_range_iterator(node_type *head) ENTT_NOEXCEPT
29  : it{head} {}
30 
31  meta_range_iterator &operator++() ENTT_NOEXCEPT {
32  return (it = it->next), *this;
33  }
34 
35  meta_range_iterator operator++(int) ENTT_NOEXCEPT {
36  meta_range_iterator orig = *this;
37  return ++(*this), orig;
38  }
39 
40  [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
41  return it;
42  }
43 
44  [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
45  return operator*();
46  }
47 
48  [[nodiscard]] bool operator==(const meta_range_iterator &other) const ENTT_NOEXCEPT {
49  return it == other.it;
50  }
51 
52  [[nodiscard]] bool operator!=(const meta_range_iterator &other) const ENTT_NOEXCEPT {
53  return !(*this == other);
54  }
55 
56 private:
57  node_type *it{};
58 };
59 
60 } // namespace internal
61 
72 template<typename Type, typename Node = typename Type::node_type>
73 struct meta_range {
75  using node_type = Node;
77  using iterator = internal::meta_range_iterator<Type, Node>;
80 
82  meta_range() ENTT_NOEXCEPT = default;
83 
89  : node{head} {}
90 
95  [[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
96  return iterator{node};
97  }
98 
100  [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
101  return cbegin();
102  }
103 
109  [[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
110  return iterator{};
111  }
112 
114  [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
115  return cend();
116  }
117 
118 private:
119  node_type *node{nullptr};
120 };
121 
122 } // namespace entt
123 
124 #endif
EnTT default namespace.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.
Definition: any.hpp:406
Iterable range to use to iterate all types of meta objects.
Definition: range.hpp:73
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition: range.hpp:95
iterator const_iterator
Constant input iterator type.
Definition: range.hpp:79
Node node_type
Node type.
Definition: range.hpp:75
const_iterator cend() const
Returns an iterator to the end.
Definition: range.hpp:109
iterator end() const
Returns an iterator to the end.
Definition: range.hpp:114
meta_range()=default
Default constructor.
iterator begin() const
Returns an iterator to the beginning.
Definition: range.hpp:100
internal::meta_range_iterator< Type, Node > iterator
Input iterator type.
Definition: range.hpp:77