EnTT  3.10.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 final {
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
27  : it{} {}
28 
29  meta_range_iterator(node_type *head) ENTT_NOEXCEPT
30  : it{head} {}
31 
32  meta_range_iterator &operator++() ENTT_NOEXCEPT {
33  return (it = it->next), *this;
34  }
35 
36  meta_range_iterator operator++(int) ENTT_NOEXCEPT {
37  meta_range_iterator orig = *this;
38  return ++(*this), orig;
39  }
40 
41  [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
42  return it;
43  }
44 
45  [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
46  return operator*();
47  }
48 
49  [[nodiscard]] bool operator==(const meta_range_iterator &other) const ENTT_NOEXCEPT {
50  return it == other.it;
51  }
52 
53  [[nodiscard]] bool operator!=(const meta_range_iterator &other) const ENTT_NOEXCEPT {
54  return !(*this == other);
55  }
56 
57 private:
58  node_type *it;
59 };
60 
61 } // namespace internal
62 
73 template<typename Type, typename Node = typename Type::node_type>
74 struct meta_range final {
76  using node_type = Node;
78  using iterator = internal::meta_range_iterator<Type, Node>;
81 
83  meta_range() ENTT_NOEXCEPT = default;
84 
89  meta_range(node_type *head) ENTT_NOEXCEPT
90  : node{head} {}
91 
96  [[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
97  return iterator{node};
98  }
99 
101  [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
102  return cbegin();
103  }
104 
110  [[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
111  return iterator{};
112  }
113 
115  [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
116  return cend();
117  }
118 
119 private:
120  node_type *node{nullptr};
121 };
122 
123 } // namespace entt
124 
125 #endif
EnTT default namespace.
Definition: dense_map.hpp:22
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:402
Iterable range to use to iterate all types of meta objects.
Definition: range.hpp:74
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition: range.hpp:96
iterator const_iterator
Constant input iterator type.
Definition: range.hpp:80
Node node_type
Node type.
Definition: range.hpp:76
const_iterator cend() const
Returns an iterator to the end.
Definition: range.hpp:110
iterator end() const
Returns an iterator to the end.
Definition: range.hpp:115
meta_range()=default
Default constructor.
iterator begin() const
Returns an iterator to the beginning.
Definition: range.hpp:101
internal::meta_range_iterator< Type, Node > iterator
Input iterator type.
Definition: range.hpp:78