8#ifndef SkEnumerate_DEFINED
9#define SkEnumerate_DEFINED
16template <
typename Iter,
typename C = std::monostate>
18 using Captured =
decltype(*std::declval<Iter>());
19 template <
typename>
struct is_tuple : std::false_type {};
20 template <
typename...
T>
struct is_tuple<
std::tuple<T...>> : std::true_type {};
23 static constexpr auto MakeResult(
size_t i, Captured&& v) {
25 return std::tuple_cat(std::tuple<size_t>{
i}, v);
28 return std::tuple_cat(std::tuple<size_t>{
i}, std::tie(v));
32 using Result =
decltype(MakeResult(0, std::declval<Captured>()));
36 using value_type = Result;
37 using difference_type = ptrdiff_t;
38 using pointer = value_type*;
39 using reference = value_type;
40 using iterator_category = std::input_iterator_tag;
41 constexpr Iterator(ptrdiff_t index, Iter it) : fIndex{index}, fIt{it} { }
42 constexpr Iterator(
const Iterator&) =
default;
43 constexpr Iterator operator++() { ++fIndex; ++fIt;
return *
this; }
44 constexpr Iterator operator++(
int) { Iterator tmp(*
this); operator++();
return tmp; }
45 constexpr bool operator==(
const Iterator& rhs)
const {
return fIt == rhs.fIt; }
46 constexpr bool operator!=(
const Iterator& rhs)
const {
return fIt != rhs.fIt; }
47 constexpr reference
operator*() {
return MakeResult(fIndex, *fIt); }
57 : fCollection{
std::move(c)}
60 , fEnd{
std::
end(fCollection)} { }
67 constexpr Iterator
begin()
const {
return Iterator{fBeginIndex, fBegin}; }
68 constexpr Iterator
end()
const {
return Iterator{fBeginIndex + this->
ssize(), fEnd}; }
69 constexpr bool empty()
const {
return fBegin == fEnd; }
74 ptrdiff_t deltaEnd = this->
ssize() - n;
79 ptrdiff_t deltaBegin = this->
ssize() - n;
91 : fBeginIndex{beginIndex}
96 const ptrdiff_t fBeginIndex;
101template <typename C, typename Iter = decltype(std::begin(std::declval<C>()))>
105template <typename C, typename Iter = decltype(std::begin(std::declval<C>()))>
110template <class T, std::size_t N, typename Iter = decltype(std::begin(std::declval<T(&)[N]>()))>
static float next(float f)
static float prev(float f)
constexpr SkEnumerate< Iter > SkMakeEnumerate(C &c)
constexpr Iterator begin() const
constexpr SkEnumerate last(size_t n)
constexpr SkEnumerate subspan(size_t offset, size_t count)
constexpr ptrdiff_t ssize() const
constexpr SkEnumerate & operator=(const SkEnumerate &that)
constexpr SkEnumerate(C &&c)
constexpr Iterator end() const
constexpr SkEnumerate(const SkEnumerate &that)=default
constexpr bool empty() const
constexpr SkEnumerate first(size_t n)
constexpr size_t size() const
constexpr SkEnumerate(Iter begin, Iter end)
static const char * begin(const StringSlice &s)
bool operator==(C p1, const scoped_nsprotocol< C > &p2)
bool operator!=(C p1, const scoped_nsprotocol< C > &p2)
constexpr Color operator*(T value, const Color &c)