Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
98 lines (77 loc) · 2.5 KB

File metadata and controls

98 lines (77 loc) · 2.5 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// -*- c++ -*-
/*
* Copyright (c) 2010-2012, Jim Bosch
* All rights reserved.
*
* ndarray is distributed under a simple BSD-like license;
* see the LICENSE file that should be present in the root
* of the source distribution, or alternately available at:
* https://github.com/ndarray/ndarray
*/
#ifndef NDARRAY_DETAIL_StridedIterator_h_INCLUDED
#define NDARRAY_DETAIL_StridedIterator_h_INCLUDED
/**
* @file ndarray/detail/StridedIterator.h
*
* @brief Definition of StridedIterator.
*/
#include "ndarray_fwd.h"
#include <boost/iterator/iterator_facade.hpp>
namespace ndarray {
namespace detail {
/**
* @internal @brief Strided iterator for noncontiguous 1D arrays.
*
* @ingroup ndarrayInternalGroup
*/
template <typename T>
class StridedIterator : public boost::iterator_facade<
StridedIterator<T>,
T, boost::random_access_traversal_tag
>
{
public:
typedef T Value;
typedef T & Reference;
StridedIterator() : _data(0), _stride(0) {}
StridedIterator(T * data, Offset stride) : _data(data), _stride(stride) {}
StridedIterator(StridedIterator const & other) : _data(other._data), _stride(other._stride) {}
template <typename U>
StridedIterator(StridedIterator<U> const & other) : _data(other._data), _stride(other._stride) {
BOOST_STATIC_ASSERT((boost::is_convertible<U*,T*>::value));
}
StridedIterator & operator=(StridedIterator const & other) {
if (&other != this) {
_data = other._data;
_stride = other._stride;
}
return *this;
}
template <typename U>
StridedIterator & operator=(StridedIterator<U> const & other) {
BOOST_STATIC_ASSERT((boost::is_convertible<U*,T*>::value));
_data = other._data;
_stride = other._stride;
return *this;
}
private:
friend class boost::iterator_core_access;
template <typename OtherT> friend class StridedIterator;
Reference dereference() const { return *_data; }
void increment() { _data += _stride; }
void decrement() { _data -= _stride; }
void advance(Offset n) { _data += _stride * n; }
template <typename U>
Offset distance_to(StridedIterator<U> const & other) const {
return std::distance(_data, other._data) / _stride;
}
template <typename U>
bool equal(StridedIterator<U> const & other) const {
return _data == other._data;
}
T * _data;
Offset _stride;
};
} // namespace detail
} // namespace ndarray
#endif // !NDARRAY_DETAIL_StridedIterator_h_INCLUDED
Morty Proxy This is a proxified and sanitized view of the page, visit original site.