EnTT  3.8.1
range.hpp
1 #ifndef ENTT_META_RANGE_HPP
2 #define ENTT_META_RANGE_HPP
3 
4 
5 #include <cstddef>
6 #include <iterator>
7 
8 
9 namespace entt {
10 
11 
17 template<typename Type, typename Node = typename Type::node_type>
18 class meta_range {
19  struct range_iterator {
20  using difference_type = std::ptrdiff_t;
21  using value_type = Type;
22  using pointer = void;
23  using reference = value_type;
24  using iterator_category = std::input_iterator_tag;
25  using node_type = Node;
26 
27  range_iterator() ENTT_NOEXCEPT = default;
28 
29  range_iterator(node_type *head) ENTT_NOEXCEPT
30  : it{head}
31  {}
32 
33  range_iterator & operator++() ENTT_NOEXCEPT {
34  return (it = it->next), *this;
35  }
36 
37  range_iterator operator++(int) ENTT_NOEXCEPT {
38  range_iterator orig = *this;
39  return ++(*this), orig;
40  }
41 
42  [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
43  return it;
44  }
45 
46  [[nodiscard]] bool operator==(const range_iterator &other) const ENTT_NOEXCEPT {
47  return other.it == it;
48  }
49 
50  [[nodiscard]] bool operator!=(const range_iterator &other) const ENTT_NOEXCEPT {
51  return !(*this == other);
52  }
53 
54  private:
55  node_type *it{};
56  };
57 
58 public:
60  using node_type = Node;
62  using iterator = range_iterator;
63 
65  meta_range() ENTT_NOEXCEPT = default;
66 
72  : node{head}
73  {}
74 
79  [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
80  return iterator{node};
81  }
82 
88  [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
89  return iterator{};
90  }
91 
92 private:
93  node_type *node{nullptr};
94 };
95 
96 
97 }
98 
99 
100 #endif
Iterable range to use to iterate all types of meta objects.
Definition: range.hpp:18
Node node_type
Node type.
Definition: range.hpp:60
iterator begin() const ENTT_NOEXCEPT
Returns an iterator to the beginning.
Definition: range.hpp:79
meta_range() ENTT_NOEXCEPT=default
Default constructor.
iterator end() const ENTT_NOEXCEPT
Returns an iterator to the end.
Definition: range.hpp:88
range_iterator iterator
Input iterator type.
Definition: range.hpp:62
EnTT default namespace.
Definition: algorithm.hpp:13
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:368
constexpr bool operator==(const Entity entity, const null_t other)
Compares a null object and an entity identifier of any type.
Definition: entity.hpp:219