sparrow 2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
bitset_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 implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
20
21namespace sparrow
22{
23 template <class B>
24 class bitset_reference;
25
36 template <class B, bool is_const>
38 bitset_iterator<B, is_const>,
39 mpl::constify_t<B, is_const>,
40 mpl::constify_t<typename B::value_type, is_const>,
41 std::conditional_t<is_const, bool, bitset_reference<B>>,
42 std::random_access_iterator_tag>
43 {
44 public:
45
51 std::conditional_t<is_const, bool, bitset_reference<B>>,
52 std::random_access_iterator_tag>;
53 using reference = typename base_type::reference;
55
58 using size_type = typename B::size_type;
59
60 constexpr bitset_iterator() noexcept = default;
61 constexpr bitset_iterator(bitset_type* bitset, size_type index);
62
63 private:
64
65 constexpr reference dereference() const noexcept;
66 constexpr void advance(difference_type n) noexcept;
67
68 friend class iterator_access;
69 };
70
71 template <class B, bool is_const>
72 constexpr bitset_iterator<B, is_const>::bitset_iterator(bitset_type* bitset, size_type index)
73 : base_type(bitset, index)
74 {
75 }
76
77 template <class B, bool is_const>
78 constexpr auto bitset_iterator<B, is_const>::dereference() const noexcept -> reference
79 {
80 if constexpr (is_const)
81 {
82 return this->p_object->test(this->m_index);
83 }
84 else
85 {
86 return bitset_reference<B>(*this->p_object, this->m_index);
87 }
88 }
89
90 template <class B, bool is_const>
92 {
93 if (n < 0 && static_cast<size_type>(-n) > this->m_index)
94 {
95 // Prevent underflow by clamping m_index to 0
96 this->m_index = 0;
97 }
98 else
99 {
100 this->m_index = static_cast<size_type>(static_cast<difference_type>(this->m_index) + n);
101 }
102 }
103}
typename base_type::reference reference
constexpr bitset_iterator() noexcept=default
mpl::constify_t< B, is_const > bitset_type
mpl::constify_t< typename B::block_type, is_const > block_type
typename B::size_type size_type
bitset_iterator< B, is_const > self_type
pointer_index_iterator_base< self_type, mpl::constify_t< B, is_const >, mpl::constify_t< typename B::value_type, is_const >, std::conditional_t< is_const, bool, bitset_reference< B > >, std::random_access_iterator_tag > base_type
typename base_type::difference_type difference_type
A proxy reference class that provides mutable access to individual bits in a bitset.
typename constify< T, is_const >::type constify_t
Convenience alias for constify.
Definition mp_utils.hpp:807