9 #ifndef TurtleBrains_TypedRange_hpp
10 #define TurtleBrains_TypedRange_hpp
12 #include <turtle_brains/core/tb_types.hpp>
15 #include <type_traits>
20 template<
typename IndexType,
typename ValueType,
size_t kMaximumIndex, ValueType& (*AccessFunction)(const IndexType index)>
struct TypedRange
25 explicit Iterator(
const IndexType index) :
30 Iterator operator++(
void) { ++mIndex;
return *
this; }
32 bool operator==(
const Iterator& other)
const {
return mIndex == other.mIndex; }
33 bool operator!=(
const Iterator& other)
const {
return mIndex != other.mIndex; }
34 ValueType& operator*(
void)
const {
return AccessFunction(mIndex); }
41 Iterator end(
void)
const {
return Iterator{ kMaximumIndex }; }
45 template<
typename IndexType,
typename ValueType, IndexType (*SizeFunction)(
void), ValueType& (*AccessFunction)(const IndexType index)>
struct DynamicTypedRange
50 explicit Iterator(
const IndexType index) :
55 Iterator operator++(
void) { ++mIndex;
return *
this; }
57 bool operator==(
const Iterator& other)
const {
return mIndex == other.mIndex; }
58 bool operator!=(
const Iterator& other)
const {
return mIndex != other.mIndex; }
59 ValueType& operator*(
void)
const {
return AccessFunction(mIndex); }
66 Iterator end(
void)
const {
return Iterator{ SizeFunction() }; }
72 OtherTypedRange(std::function<IndexType()> sizeFunction, std::function<ValueType(IndexType)> accessFunction) :
73 mSizeFunction(sizeFunction),
74 mAccessFunction(accessFunction)
81 explicit Iterator(
const IndexType index, std::function<ValueType(IndexType)> accessFunction) :
83 mAccessFunction(accessFunction)
87 Iterator operator++(
void) { ++mIndex;
return *
this; }
89 bool operator==(
const Iterator& other)
const {
return mIndex == other.mIndex; }
90 bool operator!=(
const Iterator& other)
const {
return mIndex != other.mIndex; }
91 ValueType operator*(
void)
const {
return mAccessFunction(mIndex); }
95 std::function<ValueType(IndexType)> mAccessFunction;
99 Iterator end(
void)
const {
return Iterator{ mSizeFunction(), mAccessFunction }; }
101 std::function<IndexType()> mSizeFunction;
102 std::function<ValueType(IndexType)> mAccessFunction;
110 MapContainerType& mContainer;
113 mContainer(container)
117 using BaseIterator =
typename std::conditional<std::is_const<MapContainerType>::value,
118 typename MapContainerType::const_iterator,
119 typename MapContainerType::iterator>::type;
121 using ValueType =
typename std::conditional<std::is_const<MapContainerType>::value,
122 const typename MapContainerType::mapped_type,
typename MapContainerType::mapped_type>::type;
127 explicit Iterator(BaseIterator iterator) :
128 BaseIterator(iterator) { }
130 ValueType& operator*(
void)
const {
return (*this)->second; }
134 Iterator end(
void)
const {
return Iterator(mContainer.end()); }
135 Iterator begin(
void) {
return Iterator(mContainer.begin()); }
136 Iterator end(
void) {
return Iterator(mContainer.end()); }
Definition: tb_typed_range.hpp:48
Definition: tb_typed_range.hpp:125
Definition: tb_typed_range.hpp:79
Definition: tb_typed_range.hpp:23
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:125
Internals::ValuesOfAccessor< MapContainerType > ValuesOf(MapContainerType &container)
Definition: tb_typed_range.hpp:148
Definition: tb_typed_range.hpp:46
Definition: tb_typed_range.hpp:109
Definition: tb_typed_range.hpp:71
Definition: tb_typed_range.hpp:21