21
21
22
22
#include " concepts.hpp"
23
23
24
- namespace boost ::numeric::ublas::tag{
25
-
26
- struct sliced {};
27
- struct strided {};
28
-
29
- } // namespace boost::numeric::ublas::tag
30
-
31
24
32
25
namespace boost ::numeric::ublas {
33
26
@@ -43,21 +36,17 @@ namespace boost::numeric::ublas {
43
36
*/
44
37
45
38
39
+ // template<class unsigned_type>
40
+ // class span;
46
41
47
- // using offsets = std::vector<std::ptrdiff_t>;
48
-
49
- template <class span_tag , class unsigned_type >
50
- class span ;
51
-
52
-
53
- static constexpr inline std::size_t max = std::numeric_limits<std::size_t >::max();
54
-
55
- template <>
56
- class span <tag::strided, std::size_t >
42
+ template <integral unsigned_type>
43
+ class span
57
44
{
58
45
public:
59
- using span_tag = tag::strided;
60
- using value_type = std::size_t ;
46
+ using value_type = unsigned_type;
47
+
48
+ static constexpr inline value_type max = std::numeric_limits<value_type>::max();
49
+
61
50
62
51
// covers the complete range of one dimension
63
52
// e.g. a(:)
@@ -92,6 +81,13 @@ class span<tag::strided, std::size_t>
92
81
}
93
82
}
94
83
84
+ // covers a linear range of one dimension
85
+ // e.g. a(1:n)
86
+ span (value_type f, value_type l)
87
+ : span(f,1 ,l)
88
+ {
89
+ }
90
+
95
91
// covers only one index of one dimension
96
92
// e.g. a(1) or a(end)
97
93
span (value_type n)
@@ -142,105 +138,34 @@ class span<tag::strided, std::size_t>
142
138
value_type first_, last_ , step_, size_;
143
139
};
144
140
145
- using strided_span = span<tag::strided, std::size_t >;
146
-
147
- } // namespace
148
-
149
-
150
- // ///////////
151
-
152
- namespace boost ::numeric::ublas {
153
-
154
- template <>
155
- class span <tag::sliced, std::size_t > :
156
- private span<tag::strided, std::size_t >
157
- {
158
- using super_type = span<tag::strided,std::size_t >;
159
- public:
160
- using span_tag = tag::sliced;
161
- using value_type = typename super_type::value_type;
162
- constexpr explicit span ()
163
- : super_type()
164
- {
165
- }
166
-
167
- span (value_type f, value_type l)
168
- : super_type(f, value_type(1 ), l )
169
- {
170
- }
171
-
172
- span (value_type n)
173
- : super_type(n)
174
- {
175
- }
176
-
177
- span (span const & other)
178
- : super_type(other)
179
- {
180
- }
181
-
182
- inline span& operator =(const span &other)
183
- {
184
- super_type::operator =(other);
185
- return *this ;
186
- }
187
-
188
- ~span () = default ;
189
-
190
- inline value_type operator [] (std::size_t idx) const
191
- {
192
- return super_type::operator [](idx);
193
- }
194
-
195
- inline auto first () const {return super_type::first (); }
196
- inline auto last () const {return super_type::last (); }
197
- inline auto step () const {return super_type::step (); }
198
- inline auto size () const {return super_type::size (); }
199
-
200
- inline span operator ()(const span &rhs) const
201
- {
202
- auto const & lhs = *this ;
203
- return span ( rhs.first_ + lhs.first_ , rhs.last_ + lhs.first_ );
204
- }
205
- };
206
-
207
- using sliced_span = span<tag::sliced, std::size_t >;
208
-
209
-
210
- template <integral unsigned_type_left, integral unsigned_type_right>
211
- inline auto ran (unsigned_type_left f, unsigned_type_right l)
212
- {
213
- return sliced_span (f,l);
214
- }
215
-
216
- template <integral unsigned_type_left, integral unsigned_type_middle, integral unsigned_type_right>
217
- inline auto ran (unsigned_type_left f, unsigned_type_middle s, unsigned_type_right l)
218
- {
219
- return strided_span (f,s,l);
220
- }
141
+ using sspan = span<std::size_t >;
221
142
222
143
} // namespace
223
144
224
145
225
- template <class span_tag , class unsigned_type >
226
- std::ostream& operator << (std::ostream& out, boost::numeric::ublas::span<span_tag, unsigned_type> const & s)
146
+ template <boost::numeric::ublas::integral unsigned_type>
147
+ std::ostream& operator << (std::ostream& out, boost::numeric::ublas::span<unsigned_type> const & s)
227
148
{
228
149
return out << " [" << s.first () << " :" << s.step () << " :" << s.last () << " ]" << std::endl;
229
150
}
230
151
231
- template <class span_tag_lhs , class span_tag_rhs , class unsigned_type >
152
+ template <
153
+ boost::numeric::ublas::integral unsigned_type_lhs,
154
+ boost::numeric::ublas::integral unsigned_type_rhs>
232
155
inline bool operator ==(
233
- boost::numeric::ublas::span<span_tag_lhs,unsigned_type > const & lhs,
234
- boost::numeric::ublas::span<span_tag_rhs,unsigned_type > const & rhs)
156
+ boost::numeric::ublas::span<unsigned_type_lhs > const & lhs,
157
+ boost::numeric::ublas::span<unsigned_type_rhs > const & rhs)
235
158
{
236
159
return lhs.first () == rhs.first () && lhs.last () == rhs.last () && lhs.step () == rhs.step ();
237
160
}
238
161
239
162
240
- template <class span_tag_lhs , class span_tag_rhs , class unsigned_type >
163
+ template <
164
+ boost::numeric::ublas::integral unsigned_type_lhs,
165
+ boost::numeric::ublas::integral unsigned_type_rhs>
241
166
inline bool operator !=(
242
- boost::numeric::ublas::span<span_tag_lhs,unsigned_type > const & lhs,
243
- boost::numeric::ublas::span<span_tag_rhs,unsigned_type > const & rhs)
167
+ boost::numeric::ublas::span<unsigned_type_lhs > const & lhs,
168
+ boost::numeric::ublas::span<unsigned_type_rhs > const & rhs)
244
169
{
245
170
return lhs.first () != rhs.first () || lhs.last () != rhs.last () || lhs.step () != rhs.step ();
246
171
}
0 commit comments