sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
functor_index_iterator.hpp
Go to the documentation of this file.
1
// Copyright 2024 Man Group Operations Limited
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or mplied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#pragma once
16
17
#include "
sparrow/utils/contracts.hpp
"
18
#include "
sparrow/utils/iterator.hpp
"
19
20
namespace
sparrow
21
{
22
template
<
class
FUNCTOR>
23
class
functor_index_iterator
:
public
iterator_base
<
24
functor_index_iterator<FUNCTOR>,
// Derived
25
std::invoke_result_t<FUNCTOR, std::size_t>,
// Element
26
std::random_access_iterator_tag,
27
std::invoke_result_t<FUNCTOR, std::size_t>
// Reference
28
>
29
{
30
public
:
31
32
using
result_type
= std::invoke_result_t<FUNCTOR, std::size_t>;
33
using
self_type
=
functor_index_iterator<FUNCTOR>
;
34
using
difference_type
= std::ptrdiff_t;
35
using
size_type
= std::size_t;
36
using
functor_type
= FUNCTOR;
37
38
constexpr
functor_index_iterator
() =
default
;
39
40
constexpr
functor_index_iterator
(FUNCTOR functor,
size_type
index)
41
: m_functor(
std
::move(functor))
42
, m_index(index)
43
{
44
}
45
46
private
:
47
48
[[nodiscard]]
result_type
dereference()
const
49
{
50
return
m_functor(m_index);
51
}
52
53
constexpr
void
increment() noexcept(
SPARROW_CONTRACTS_THROW_ON_FAILURE
== 0)
54
{
55
SPARROW_ASSERT_TRUE
(m_index < std::numeric_limits<size_type>::max());
56
++m_index;
57
}
58
59
constexpr
void
decrement() noexcept(
SPARROW_CONTRACTS_THROW_ON_FAILURE
== 0)
60
{
61
SPARROW_ASSERT_TRUE
(m_index > 0);
62
--m_index;
63
}
64
65
constexpr
void
advance(
difference_type
n)
noexcept
(
SPARROW_CONTRACTS_THROW_ON_FAILURE
== 0)
66
{
67
if
(n >= 0)
68
{
69
m_index +=
static_cast<
size_type
>
(n);
70
}
71
else
72
{
73
SPARROW_ASSERT_TRUE
(std::abs(n) <=
static_cast<
difference_type
>
(m_index));
74
m_index -=
static_cast<
size_type
>
(-n);
75
}
76
}
77
78
[[nodiscard]]
constexpr
difference_type
79
distance_to(
const
self_type
& rhs)
const
noexcept
(
SPARROW_CONTRACTS_THROW_ON_FAILURE
== 0)
80
{
81
return
static_cast<
difference_type
>
(rhs.m_index) -
static_cast<
difference_type
>
(m_index);
82
}
83
84
[[nodiscard]]
constexpr
bool
equal(
const
self_type
& rhs)
const
noexcept
85
{
86
return
m_index == rhs.m_index;
87
}
88
89
[[nodiscard]]
constexpr
bool
less_than(
const
self_type
& rhs)
const
noexcept
90
{
91
return
m_index < rhs.m_index;
92
}
93
94
FUNCTOR m_functor = FUNCTOR{};
95
size_type
m_index = 0;
96
97
friend
class
iterator_access
;
98
};
99
}
sparrow::functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > >::difference_type
std::ptrdiff_t difference_type
Definition
functor_index_iterator.hpp:34
sparrow::functor_index_iterator::functor_index_iterator
constexpr functor_index_iterator(FUNCTOR functor, size_type index)
Definition
functor_index_iterator.hpp:40
sparrow::functor_index_iterator::functor_index_iterator
constexpr functor_index_iterator()=default
sparrow::functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > >::self_type
functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > > self_type
Definition
functor_index_iterator.hpp:33
sparrow::functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > >::size_type
std::size_t size_type
Definition
functor_index_iterator.hpp:35
sparrow::functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > >::iterator_access
friend class iterator_access
Definition
functor_index_iterator.hpp:97
sparrow::functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > >::result_type
std::invoke_result_t< detail::layout_value_functor< array_type, inner_reference >, std::size_t > result_type
Definition
functor_index_iterator.hpp:32
sparrow::functor_index_iterator< detail::layout_value_functor< array_type, inner_reference > >::functor_type
detail::layout_value_functor< array_type, inner_reference > functor_type
Definition
functor_index_iterator.hpp:36
sparrow::iterator_base
Definition
iterator.hpp:381
contracts.hpp
SPARROW_ASSERT_TRUE
#define SPARROW_ASSERT_TRUE(expr__)
Definition
contracts.hpp:209
SPARROW_CONTRACTS_THROW_ON_FAILURE
#define SPARROW_CONTRACTS_THROW_ON_FAILURE
Definition
contracts.hpp:24
iterator.hpp
sparrow
Definition
array.hpp:21
std
Extensions to the C++ standard library.
Definition
float16_t.hpp:1916
sparrow
utils
functor_index_iterator.hpp
Generated by
1.17.0