8#ifndef SEN_CORE_BASE_ITERATOR_ADAPTERS_H
9#define SEN_CORE_BASE_ITERATOR_ADAPTERS_H
23template <
typename IteratorType>
28 [[nodiscard]] IteratorType
begin()
const {
return begin_; }
29 [[nodiscard]] IteratorType
end()
const {
return end_; }
30 [[nodiscard]]
bool empty()
const {
return begin_ == end_; }
51template <
typename IteratorType>
54 return {std::move(begin), std::move(end)};
70template <
typename ContainerType>
73 return makeRange(std::begin(container), std::end(container));
86template <
template <
typename>
typename LockType,
typename IteratorType,
typename MutexType>
90 template <
typename ContainerType>
92 : lock_(m), beginIterator_(
std::
begin(container)), endIterator_(
std::
end(container))
97 : lock_(m), beginIterator_(
begin), endIterator_(
end)
101 [[nodiscard]] IteratorType
begin() const noexcept(
std::is_nothrow_copy_constructible_v<IteratorType>)
103 return beginIterator_;
105 [[nodiscard]] IteratorType
end() const noexcept(
std::is_nothrow_copy_constructible_v<IteratorType>)
111 LockType<MutexType> lock_;
112 IteratorType beginIterator_;
113 IteratorType endIterator_;
131template <
template <
typename>
typename LockType,
typename IteratorType,
typename MutexType>
151template <
template <
typename>
typename LockType,
typename ContainerType,
typename MutexType>
154 if constexpr (std::is_const_v<ContainerType>)
183template <
typename IteratorType>
191 using value_type =
typename IteratorType::value_type::element_type;
213 return lhs.iter_ == rhs.iter_;
217 return !(lhs == rhs);
A range adapter to combine a range with lock.
Definition iterator_adapters.h:88
LockedRangeAdapter(IteratorType begin, IteratorType end, MutexType &m)
Definition iterator_adapters.h:96
LockedRangeAdapter(ContainerType &container, MutexType &m)
Definition iterator_adapters.h:91
IteratorType begin() const noexcept(std::is_nothrow_copy_constructible_v< IteratorType >)
Definition iterator_adapters.h:101
IteratorType end() const noexcept(std::is_nothrow_copy_constructible_v< IteratorType >)
Definition iterator_adapters.h:105
Definition iterator_adapters.h:16
auto makeLockedRange(IteratorType begin, IteratorType end, MutexType &m)
Create a LockedRangeAdapter for the given iterator pair and lock the given mutex.
Definition iterator_adapters.h:132
IteratorRange< IteratorType > makeRange(IteratorType begin, IteratorType end)
Create a simple range for the two iterators.
Definition iterator_adapters.h:52
Basic range abstraction to form a minimal range around two iterators.
Definition iterator_adapters.h:25
util::SmartPtrIteratorAdapter< UnitStorage::const_iterator > begin() const
Definition iterator_adapters.h:28
util::SmartPtrIteratorAdapter< UnitStorage::const_iterator > end() const
Definition iterator_adapters.h:29
bool empty() const
Definition iterator_adapters.h:30
IteratorRange(IteratorType begin, IteratorType end)
Definition iterator_adapters.h:26
pointer operator*() const
Definition iterator_adapters.h:196
typename IteratorType::iterator_category iterator_category
Definition iterator_adapters.h:189
std::ptrdiff_t difference_type
Definition iterator_adapters.h:190
SmartPtrIteratorAdapter & operator++()
Definition iterator_adapters.h:199
friend bool operator!=(const SmartPtrIteratorAdapter &lhs, const SmartPtrIteratorAdapter &rhs)
Definition iterator_adapters.h:215
friend bool operator==(const SmartPtrIteratorAdapter &lhs, const SmartPtrIteratorAdapter &rhs)
Definition iterator_adapters.h:211
SmartPtrIteratorAdapter(IteratorType iter)
Definition iterator_adapters.h:186
typename IteratorType::value_type::element_type value_type
Definition iterator_adapters.h:191
reference operator->() const
Definition iterator_adapters.h:197
value_type & reference
Definition iterator_adapters.h:193
value_type * pointer
Definition iterator_adapters.h:192
SmartPtrIteratorAdapter operator++(int)
Definition iterator_adapters.h:204