libstdc++
simd_iterator.h
1// Implementation of <simd> -*- C++ -*-
2
3// Copyright The GNU Toolchain Authors.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25#ifndef _GLIBCXX_SIMD_ITERATOR_H
26#define _GLIBCXX_SIMD_ITERATOR_H 1
27
28#ifdef _GLIBCXX_SYSHDR
29#pragma GCC system_header
30#endif
31
32#if __cplusplus >= 202400L
33
34#include "simd_details.h"
35
36namespace std _GLIBCXX_VISIBILITY(default)
37{
38_GLIBCXX_BEGIN_NAMESPACE_VERSION
39namespace simd
40{
41 /** @internal
42 * Iterator type for basic_vec and basic_mask.
43 *
44 * C++26 [simd.iterator]
45 */
46 template <typename _Vp>
47 class __iterator
48 {
49 friend class __iterator<const _Vp>;
50
51 template <typename, typename>
52 friend class _VecBase;
53
54 template <size_t, typename>
55 friend class _MaskBase;
56
57 _Vp* _M_data = nullptr;
58
59 __simd_size_type _M_offset = 0;
60
61 constexpr
62 __iterator(_Vp& __d, __simd_size_type __off)
63 : _M_data(&__d), _M_offset(__off)
64 {}
65
66 public:
67 using value_type = typename _Vp::value_type;
68
69 using iterator_category = input_iterator_tag;
70
71 using iterator_concept = random_access_iterator_tag;
72
73 using difference_type = __simd_size_type;
74
75 constexpr __iterator() = default;
76
77 constexpr
78 __iterator(const __iterator &) = default;
79
80 constexpr __iterator&
81 operator=(const __iterator &) = default;
82
83 constexpr
84 __iterator(const __iterator<remove_const_t<_Vp>> &__i) requires is_const_v<_Vp>
85 : _M_data(__i._M_data), _M_offset(__i._M_offset)
86 {}
87
88 constexpr value_type
89 operator*() const
90 { return (*_M_data)[_M_offset]; } // checked in operator[]
91
92 constexpr __iterator&
93 operator++()
94 {
95 ++_M_offset;
96 return *this;
97 }
98
99 constexpr __iterator
100 operator++(int)
101 {
102 __iterator r = *this;
103 ++_M_offset;
104 return r;
105 }
106
107 constexpr __iterator&
108 operator--()
109 {
110 --_M_offset;
111 return *this;
112 }
113
114 constexpr __iterator
115 operator--(int)
116 {
117 __iterator r = *this;
118 --_M_offset;
119 return r;
120 }
121
122 constexpr __iterator&
123 operator+=(difference_type __x)
124 {
125 _M_offset += __x;
126 return *this;
127 }
128
129 constexpr __iterator&
130 operator-=(difference_type __x)
131 {
132 _M_offset -= __x;
133 return *this;
134 }
135
136 constexpr value_type
137 operator[](difference_type __i) const
138 { return (*_M_data)[_M_offset + __i]; } // checked in operator[]
139
140 constexpr friend bool operator==(__iterator __a, __iterator __b) = default;
141
142 constexpr friend bool operator==(__iterator __a, std::default_sentinel_t) noexcept
143 { return __a._M_offset == _Vp::size.value; }
144
145 constexpr friend auto operator<=>(__iterator __a, __iterator __b)
146 { return __a._M_offset <=> __b._M_offset; }
147
148 constexpr friend __iterator
149 operator+(const __iterator& __it, difference_type __x)
150 { return __iterator(*__it._M_data, __it._M_offset + __x); }
151
152 constexpr friend __iterator
153 operator+(difference_type __x, const __iterator& __it)
154 { return __iterator(*__it._M_data, __it._M_offset + __x); }
155
156 constexpr friend __iterator
157 operator-(const __iterator& __it, difference_type __x)
158 { return __iterator(*__it._M_data, __it._M_offset - __x); }
159
160 constexpr friend difference_type
161 operator-(__iterator __a, __iterator __b)
162 { return __a._M_offset - __b._M_offset; }
163
164 constexpr friend difference_type
165 operator-(__iterator __it, std::default_sentinel_t) noexcept
166 { return __it._M_offset - difference_type(_Vp::size.value); }
167
168 constexpr friend difference_type
169 operator-(std::default_sentinel_t, __iterator __it) noexcept
170 { return difference_type(_Vp::size.value) - __it._M_offset; }
171 };
172} // namespace simd
173_GLIBCXX_END_NAMESPACE_VERSION
174} // namespace std
175
176#endif // C++26
177#endif // _GLIBCXX_SIMD_ITERATOR_H
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
Definition complex:434
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
Definition complex:404
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
Definition complex:374
ISO C++ entities toplevel namespace is std.