2#include "gaia/config/config.h"
20 template <
typename,
typename =
void>
21 struct iterator_traits_base {};
23 template <
typename It>
24 struct iterator_traits_base<
26 typename It::iterator_category, typename It::value_type, typename It::difference_type,
27 typename It::pointer, typename It::reference>> {
28 using iterator_category =
typename It::iterator_category;
29 using value_type =
typename It::value_type;
30 using difference_type =
typename It::difference_type;
31 using pointer =
typename It::pointer;
32 using reference =
typename It::reference;
35 template <
typename T,
bool = std::is_
object_v<T>>
36 struct iterator_traits_pointer_base {
37 using iterator_category = random_access_iterator_tag;
38 using value_type = std::remove_cv_t<T>;
39 using difference_type = std::ptrdiff_t;
46 struct iterator_traits_pointer_base<T, false> {};
49 template <
typename It>
50 struct iterator_traits: iterator_traits_base<It> {};
54 struct iterator_traits<T*>: iterator_traits_pointer_base<T> {};
56 template <
typename It>
57 using iterator_cat_t =
typename iterator_traits<It>::iterator_category;
63 template <
typename T,
typename =
void>
64 [[maybe_unused]]
constexpr bool is_iterator_v =
false;
69 [[maybe_unused]]
constexpr bool is_iterator_v<T, std::void_t<detail::iterator_cat_t<T>>> =
true;
76 template <
typename It>
77 [[maybe_unused]]
constexpr bool is_input_iter_v =
82 template <
typename It>
83 [[maybe_unused]]
constexpr bool is_fwd_iter_v =
88 template <
typename It>
89 [[maybe_unused]]
constexpr bool is_rev_iter_v =
94 template <
typename It>
95 [[maybe_unused]]
constexpr bool is_bidi_iter_v =
100 template <
typename It>
101 [[maybe_unused]]
constexpr bool is_random_iter_v =
106 template <
typename It>
107 using iterator_ref_t =
typename detail::iterator_traits<It>::reference;
111 template <
typename It>
112 using iterator_value_t =
typename detail::iterator_traits<It>::value_type;
116 template <
typename It>
117 using iterator_diff_t =
typename detail::iterator_traits<It>::difference_type;
121 template <
typename... It>
122 using common_diff_t = std::common_type_t<iterator_diff_t<It>...>;
129 template <
typename It>
130 constexpr iterator_diff_t<It> distance(It first, It last) {
131 if constexpr (std::is_pointer_v<It> || is_random_iter_v<It>)
134 iterator_diff_t<It> offset{};
135 while (first != last) {