8#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_MAP_REFERENCE_ITERATOR_HPP_
9#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_MAP_REFERENCE_ITERATOR_HPP_
16#include "arene/base/detail/iterator_interface.hpp"
18#include "arene/base/stdlib_choice/cstddef.hpp"
19#include "arene/base/stdlib_choice/enable_if.hpp"
20#include "arene/base/stdlib_choice/integral_constant.hpp"
21#include "arene/base/stdlib_choice/is_base_of.hpp"
22#include "arene/base/stdlib_choice/is_const.hpp"
23#include "arene/base/stdlib_choice/iterator_tags.hpp"
24#include "arene/base/stdlib_choice/iterator_traits.hpp"
25#include "arene/base/stdlib_choice/remove_reference.hpp"
34namespace inline_map_reference_iterator_detail {
37auto value_at_index() -> void;
58template <
class MapBase,
bool IsConst>
60 :
public detail::iterator_interface<inline_map_reference_iterator<MapBase, IsConst>>
61 , inline_map_detail::inline_map_passkey_base<MapBase> {
64 using iterator_interface = detail::iterator_interface<inline_map_reference_iterator>;
70 template <
class T,
bool B = IsConst>
74 using inline_map_passkey =
typename inline_map_detail::inline_map_passkey_base<MapBase>::inline_map_passkey;
90 using pointer = maybe_const_t<value_type>*;
102 static constexpr bool is_const_iterator_v{
119 using erased_index_fn_type =
auto (*)(maybe_const_t<map_base_type, B>*, index_type) -> maybe_const_t<value_type, B>&;
130 erased_index_fn_type<false> non_const_erased_index_;
139 erased_index_fn_type<true> const_erased_index_;
143 maybe_const_t<map_base_type>* map_;
183 template <
bool True, constra
ints<std::enable_if_t<IsConst && True>> =
nullptr>
185 return const_erased_index_(map_, pos_);
193 template <
bool False, constra
ints<std::enable_if_t<!IsConst && !False>> =
nullptr>
195 return non_const_erased_index_(map_, pos_);
205 template <
bool B,
class Map>
206 static auto value_in_map(maybe_const_t<MapBase, B>* map, index_type index)
noexcept -> maybe_const_t<value_type, B>& {
207 using ::arene::base::inline_map_reference_iterator_detail::value_at_index;
208 return value_at_index(inline_map_passkey{}, *
static_cast<maybe_const_t<Map, B>*
>(map), index);
215 : iterator_interface{},
216 non_const_erased_index_{
nullptr},
217 const_erased_index_{
nullptr},
231 : iterator_interface{},
232 non_const_erased_index_{&value_in_map<false, typename I::inline_map_type>},
233 const_erased_index_{&value_in_map<true, typename I::inline_map_type>},
234 map_{itr.get_map(inline_map_passkey{})},
235 pos_{itr.get_index(inline_map_passkey{})} {}
241 template <
bool OtherConst, constra
ints<std::enable_if_t<IsConst && !OtherConst>> =
nullptr>
244 : iterator_interface{},
245 non_const_erased_index_{other.non_const_erased_index_},
246 const_erased_index_{other.const_erased_index_},
266 return lhs.pos_ == rhs.pos_;
278 auto get_map(inline_map_passkey)
const noexcept -> maybe_const_t<map_base_type>* {
return map_; }
283 auto get_index(inline_map_passkey)
const noexcept -> index_type {
return pos_; }
auto get_index(inline_map_passkey) const noexcept -> index_type
obtain the position that this iterator references within the map
Definition map_reference_iterator.hpp:283
inline_map_reference_iterator(I const &itr) noexcept
construct from an inline_map iterator type
Definition map_reference_iterator.hpp:230
std::ptrdiff_t difference_type
Definition map_reference_iterator.hpp:88
friend auto step_forward(detail::iterator_interface_tag, inline_map_reference_iterator &iter) noexcept -> void
basis function for increment
Definition map_reference_iterator.hpp:161
MapBase map_base_type
Definition map_reference_iterator.hpp:95
inline_map_reference_iterator(inline_map_reference_iterator< MapBase, OtherConst > const &other) noexcept
implictly construct from a non-const inline_map_reference_iterator
Definition map_reference_iterator.hpp:243
friend auto step_backward(detail::iterator_interface_tag, inline_map_reference_iterator &iter) noexcept -> void
basis function for decrement
Definition map_reference_iterator.hpp:168
inline_map_reference_iterator() noexcept
default construct an invalid iterator
Definition map_reference_iterator.hpp:214
auto operator*() const noexcept -> reference
dereference
Definition map_reference_iterator.hpp:253
auto get_map(inline_map_passkey) const noexcept -> maybe_const_t< map_base_type > *
obtain a pointer to the map that this iterator references
Definition map_reference_iterator.hpp:278
maybe_const_t< value_type > & reference
Definition map_reference_iterator.hpp:92
maybe_const_t< value_type > * pointer
Definition map_reference_iterator.hpp:90
std::bidirectional_iterator_tag iterator_category
Definition map_reference_iterator.hpp:84
typename MapBase::value_type value_type
Definition map_reference_iterator.hpp:86
friend auto operator==(inline_map_reference_iterator const &lhs, inline_map_reference_iterator const &rhs) noexcept -> bool
equality
Definition map_reference_iterator.hpp:264
An empty tag type corresponding to a bidirectional iterator.
Definition iterator_tags.hpp:25
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
static constexpr value_type value
Definition integral_constant.hpp:34
A type trait to check if a type is const. The class is derived from true_type if Type is const,...
Definition is_const.hpp:32
Definition accumulate.hpp:37
typename static_if< B >::template then_else< T, F > conditional_t
lazily select between two types based on a boolean condition
Definition conditional.hpp:28
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
::ptrdiff_t ptrdiff_t
A type suitable for holding the difference between two pointers.
Definition cstddef.hpp:31
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41