/usr/include/linbox/vector/subiterator.h is in liblinbox-dev 1.3.2-1.1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | /* linbox/vector/subiterator.h
* Copyright (C) 2002 William J. Turner
*
* Written by William J. Turner <wjturner@acm.org>
* Mods by -bds
* ------------------------------------
*
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*.
*/
#ifndef __LINBOX_subiterator_H
#define __LINBOX_subiterator_H
#include <iterator>
#include <vector>
// namespace in which all LinBox code resides
namespace LinBox
{
/** \brief Subvector iterator class provides striding iterators.
\ingroup vector
* A Subiterator steps by a fixed stride thru the underlying container.
* Subiter<Iterator> requires that Iterator be a random access iterator class
* and then itself provides the full functionality of a random access iterator
* class. See STL documentation for that functionality.
* Documented here is only the constructor from (1) an iterator of an
* underlying container and (2) a stride amount.
*/
template <typename Iterator>
class Subiterator {
public:
// Types
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
typedef typename std::iterator_traits<Iterator>::pointer pointer;
typedef typename std::iterator_traits<Iterator>::reference reference;
// Constructors
Subiterator () {}
/** Subiterator p (pp, 3) provides an iterator which initially has
* the same reference, but for which increments and offsets step by
* the amount stride rather than 1.
* Thus p+k is equivalent to pp+(stride*k).
*
* Striding iterators are easily positioned beyond the bounds of the
* underlying container. It is up to the user to dereference the
* iterator only when it has a valid reference.
*/
Subiterator (const Iterator &iter, const difference_type& stride = 1) :
_iter (iter), _stride (stride) {}
template<class Iterator2>
Subiterator (const Subiterator<Iterator2>& iter) :
_iter (iter._iter), _stride (iter._stride) {}
template<class Iterator2>
Subiterator& operator = (const Subiterator<Iterator2>& sub)
{
_iter=sub._iter;
_stride=sub._stride;
return *this;
}
// Access operations
reference operator * () const
{ return *_iter; }
Iterator operator -> () const
{ return _iter; }
reference operator [] (difference_type n) const
{ return _iter[n * _stride]; }
// Iteration operations
Subiterator& operator ++ ()
{ _iter += _stride; return *this; }
Subiterator operator ++ (int)
{ Subiterator tmp = *this; _iter += _stride; return tmp; }
Subiterator& operator -- ()
{ _iter -= _stride; return *this; }
Subiterator operator -- (int)
{ Subiterator tmp = *this; _iter -= _stride; return tmp; }
Subiterator operator + (difference_type n) const
{ return Subiterator (_iter + (n * _stride), _stride); }
Subiterator& operator += (difference_type n)
{ _iter += (n * _stride); return *this; }
Subiterator operator - (difference_type n) const
{ return Subiterator (_iter - (n * _stride), _stride); }
difference_type operator - (const Subiterator& x) const
{ return (_iter - x._iter)/_stride; }
Subiterator& operator -= (difference_type n)
{ _iter -= (n * _stride); return *this; }
// Comparison operations
bool operator == (const Subiterator& i) const
{ return ( (this->_stride == i._stride) && (this->_iter == i._iter) ); }
bool operator != (const Subiterator& i) const
{ return !(*this == i); }
bool operator < (const Subiterator& i) const
{ return (this->_iter < i._iter); }
bool operator > (const Subiterator& i) const
{ return (this->_iter > i._iter); }
bool operator <= (const Subiterator& i) const
{ return (this->_iter <= i._iter); }
bool operator >= (const Subiterator& i) const
{ return (this->_iter >= i._iter); }
void swap (Subiterator& x)
{ std::swap (_iter, x._iter); std::swap (_stride, x._stride); }
protected:
Iterator _iter; // wrapped iterator
difference_type _stride; // length between iterations
}; // template <class Iterator> class Subiterator
} // namespace LinBox
#endif // __LINBOX_subiterator_H
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,:0,t0,+0,=s
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
|