OpenStructure
Loading...
Searching...
No Matches
pointer_iterator.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of the OpenStructure project <www.openstructure.org>
3//
4// Copyright (C) 2008-2020 by the OpenStructure authors
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License as published by the Free
8// Software Foundation; either version 3.0 of the License, or (at your option)
9// any later version.
10// This library is distributed in the hope that it will be useful, but WITHOUT
11// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13// details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with this library; if not, write to the Free Software Foundation, Inc.,
17// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18//------------------------------------------------------------------------------
19#ifndef OST_MOL_IMPL_POINTER_ITERATOR_HH
20#define OST_MOL_IMPL_POINTER_ITERATOR_HH
21
22#include <vector>
23
24namespace ost { namespace mol { namespace impl {
25
26template <typename T>
28
29 using iterator_category = std::forward_iterator_tag;
30 using value_type = T;
31 using difference_type = std::ptrdiff_t;
32 using pointer = T*;
33 using reference = T&;
34
35public:
36 pointer_it(T* s): s_(s) { }
37
39 {
40 ++s_;
41 return *this;
42 }
44 {
45 s_+=rhs;
46 return *this;
47 }
48
49 bool operator==(const pointer_it<T>& rhs) const
50 {
51 return rhs.s_==s_;
52 }
53
54 bool operator!=(const pointer_it<T>&rhs) const
55 {
56 return !(*this==rhs);
57 }
58
60 {
61 return *s_;
62 }
63
65 {
66 return s_;
67 }
68private:
69 T* s_;
70};
71
72template <typename T>
73inline pointer_it<T> begin(const std::vector<T>& values)
74{
75 return pointer_it<T>(values.empty() ? NULL : const_cast<T*>(&values.front()));
76}
77
78template <typename T>
79inline pointer_it<T> end(const std::vector<T>& values)
80{
81 return pointer_it<T>(values.empty() ? NULL : const_cast<T*>(&values.back()+1));
82}
83
84}}}
85
86#endif
bool operator==(const pointer_it< T > &rhs) const
bool operator!=(const pointer_it< T > &rhs) const
pointer_it< T > & operator++()
pointer_it< T > & operator+(int rhs)
pointer_it< T > begin(const std::vector< T > &values)
pointer_it< T > end(const std::vector< T > &values)
Definition base.dox:1