EnTT  3.9.0
iterator.hpp
1 #ifndef ENTT_CORE_ITERATOR_HPP
2 #define ENTT_CORE_ITERATOR_HPP
3 
4 #include <iterator>
5 #include <memory>
6 #include <utility>
7 #include "../config/config.h"
8 
9 namespace entt {
10 
15 template<typename Type>
16 struct input_iterator_pointer final {
18  using pointer = decltype(std::addressof(std::declval<Type &>()));
19 
22 
25 
31  : value{std::move(val)} {}
32 
38 
44 
49  [[nodiscard]] pointer operator->() ENTT_NOEXCEPT {
50  return std::addressof(value);
51  }
52 
53 private:
54  Type value;
55 };
56 
61 template<typename It>
62 struct iterable_adaptor final {
64  using value_type = typename std::iterator_traits<It>::value_type;
66  using iterator = It;
69 
71  iterable_adaptor() = default;
72 
78  iterable_adaptor(It from, It to)
79  : first{from},
80  last{to} {}
81 
86  [[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
87  return first;
88  }
89 
95  [[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
96  return last;
97  }
98 
100  [[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
101  return begin();
102  }
103 
105  [[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
106  return end();
107  }
108 
109 private:
110  It first;
111  It last;
112 };
113 
114 } // namespace entt
115 
116 #endif
EnTT default namespace.
Helper type to use as pointer with input iterators.
Definition: iterator.hpp:16
input_iterator_pointer & operator=(input_iterator_pointer &&)=default
Default move assignment operator.
input_iterator_pointer(input_iterator_pointer &&)=default
Default move constructor.
input_iterator_pointer(const input_iterator_pointer &)=delete
Default copy constructor, deleted on purpose.
pointer operator->()
Access operator for accessing wrapped values.
Definition: iterator.hpp:49
input_iterator_pointer & operator=(const input_iterator_pointer &)=delete
Default copy assignment operator, deleted on purpose.
decltype(std::addressof(std::declval< Type & >())) pointer
Pointer type.
Definition: iterator.hpp:18
input_iterator_pointer(Type &&val)
Constructs a proxy object by move.
Definition: iterator.hpp:30
Utility class to create an iterable object from a pair of iterators.
Definition: iterator.hpp:62
const_iterator begin() const
Returns an iterator to the beginning.
Definition: iterator.hpp:86
iterable_adaptor()=default
Default constructor.
const_iterator end() const
Returns an iterator to the end.
Definition: iterator.hpp:95
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition: iterator.hpp:100
typename std::iterator_traits< It >::value_type value_type
Type of the objects returned during iteration.
Definition: iterator.hpp:64
const_iterator cend() const
Returns an iterator to the end.
Definition: iterator.hpp:105
It iterator
Iterator type.
Definition: iterator.hpp:66
iterator const_iterator
Const iterator type.
Definition: iterator.hpp:68
iterable_adaptor(It from, It to)
Creates an iterable object from a pair of iterators.
Definition: iterator.hpp:78