My Project
IteratorRange.hpp
1/*
2 Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
3 Copyright 2009, 2010 Statoil ASA.
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef OPM_ITERATOR_RANGE_HEADER
21#define OPM_ITERATOR_RANGE_HEADER
22
23#include <iterator>
24#include <type_traits>
25
26namespace Opm {
27
28template <class DataType>
30 iterator_range_pod(const DataType* begin, const DataType* end) : begin_(begin), end_(end) {}
31 iterator_range_pod() = default;
32
33 size_t size() const { return std::distance(begin_,end_); }
34 bool empty() const { return begin_ == end_; }
35 bool operator==(const iterator_range_pod<DataType>& rhs) const
36 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
37
38 const DataType& operator[](int idx) const { return begin_[idx]; }
39
40 const DataType* begin() const { return begin_; }
41 const DataType* end() const { return end_; }
42
43protected:
44 const DataType* begin_;
45 const DataType* end_;
46
47};
48
49template <class Iter>
51 iterator_range(Iter begin, Iter end) : begin_(begin), end_(end) {}
52 iterator_range() = default;
53
54 size_t size() const { return std::distance(begin_,end_); }
55 bool empty() const { return begin_ == end_; }
56 bool operator==(const iterator_range<Iter>& rhs) const
57 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
58
59 const typename Iter::value_type& operator[](int idx) const
60 { return *(begin_+ idx); }
61
62 Iter begin() const { return begin_; }
63 Iter end() const { return end_; }
64
65protected:
66 Iter begin_, end_;
67};
68
69template<typename Iter>
71 mutable_iterator_range(Iter begin, Iter end) : begin_(begin), end_(end) {}
72 mutable_iterator_range() = default;
73
74 size_t size() const { return std::distance(begin_,end_); }
75 bool empty() const { return begin_ == end_; }
76 bool operator==(const Iter& rhs) const
77 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
78
79 typename Iter::value_type& operator[](int idx)
80 { return begin_[idx]; }
81
82 Iter begin() const { return begin_; }
83 Iter end() const { return end_; }
84
85protected:
86 Iter begin_, end_;
87};
88
89}
90
91#endif // OPM_ITERATOR_RANGE_HEADER
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:29
Definition: IteratorRange.hpp:29
Definition: IteratorRange.hpp:50
Definition: IteratorRange.hpp:70