IteratorRange.hpp
Go to the documentation of this file.
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_; }
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>
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>
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:26
Definition: IteratorRange.hpp:29
bool empty() const
Definition: IteratorRange.hpp:34
bool operator==(const iterator_range_pod< DataType > &rhs) const
Definition: IteratorRange.hpp:35
const DataType * begin_
Definition: IteratorRange.hpp:44
iterator_range_pod(const DataType *begin, const DataType *end)
Definition: IteratorRange.hpp:30
size_t size() const
Definition: IteratorRange.hpp:33
const DataType * begin() const
Definition: IteratorRange.hpp:40
const DataType * end() const
Definition: IteratorRange.hpp:41
const DataType * end_
Definition: IteratorRange.hpp:45
const DataType & operator[](int idx) const
Definition: IteratorRange.hpp:38
Definition: IteratorRange.hpp:50
Iter end_
Definition: IteratorRange.hpp:66
Iter begin_
Definition: IteratorRange.hpp:66
size_t size() const
Definition: IteratorRange.hpp:54
bool empty() const
Definition: IteratorRange.hpp:55
Iter end() const
Definition: IteratorRange.hpp:63
const Iter::value_type & operator[](int idx) const
Definition: IteratorRange.hpp:59
bool operator==(const iterator_range< Iter > &rhs) const
Definition: IteratorRange.hpp:56
Iter begin() const
Definition: IteratorRange.hpp:62
iterator_range()=default
iterator_range(Iter begin, Iter end)
Definition: IteratorRange.hpp:51
Definition: IteratorRange.hpp:70
Iter begin_
Definition: IteratorRange.hpp:86
size_t size() const
Definition: IteratorRange.hpp:74
bool operator==(const Iter &rhs) const
Definition: IteratorRange.hpp:76
Iter::value_type & operator[](int idx)
Definition: IteratorRange.hpp:79
Iter begin() const
Definition: IteratorRange.hpp:82
Iter end() const
Definition: IteratorRange.hpp:83
bool empty() const
Definition: IteratorRange.hpp:75
Iter end_
Definition: IteratorRange.hpp:86
mutable_iterator_range(Iter begin, Iter end)
Definition: IteratorRange.hpp:71