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
26#include <opm/common/utility/gpuDecorators.hpp>
27
28namespace Opm {
29
30template <class DataType>
32 OPM_HOST_DEVICE iterator_range_pod(const DataType* begin, const DataType* end) : begin_(begin), end_(end) {}
33 iterator_range_pod() = default;
34
35 OPM_HOST_DEVICE size_t size() const { return std::distance(begin_,end_); }
36 OPM_HOST_DEVICE bool empty() const { return begin_ == end_; }
37 OPM_HOST_DEVICE bool operator==(const iterator_range_pod<DataType>& rhs) const
38 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
39
40 OPM_HOST_DEVICE const DataType& operator[](int idx) const { return begin_[idx]; }
41
42 OPM_HOST_DEVICE const DataType* begin() const { return begin_; }
43 OPM_HOST_DEVICE const DataType* end() const { return end_; }
44
45protected:
46 const DataType* begin_;
47 const DataType* end_;
48
49};
50
51template <class Iter>
53 OPM_HOST_DEVICE iterator_range(Iter begin, Iter end) : begin_(begin), end_(end) {}
54 iterator_range() = default;
55
56 OPM_HOST_DEVICE size_t size() const { return std::distance(begin_,end_); }
57 OPM_HOST_DEVICE bool empty() const { return begin_ == end_; }
58 OPM_HOST_DEVICE bool operator==(const iterator_range<Iter>& rhs) const
59 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
60
61 OPM_HOST_DEVICE const typename Iter::value_type& operator[](int idx) const
62 { return *(begin_+ idx); }
63
64 OPM_HOST_DEVICE Iter begin() const { return begin_; }
65 OPM_HOST_DEVICE Iter end() const { return end_; }
66
67protected:
68 Iter begin_, end_;
69};
70
71template<typename Iter>
73 OPM_HOST_DEVICE mutable_iterator_range(Iter begin, Iter end) : begin_(begin), end_(end) {}
75
76 OPM_HOST_DEVICE size_t size() const { return std::distance(begin_,end_); }
77 OPM_HOST_DEVICE bool empty() const { return begin_ == end_; }
78 OPM_HOST_DEVICE bool operator==(const Iter& rhs) const
79 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
80
81 OPM_HOST_DEVICE typename Iter::value_type& operator[](int idx)
82 { return begin_[idx]; }
83
84 OPM_HOST_DEVICE Iter begin() const { return begin_; }
85 OPM_HOST_DEVICE Iter end() const { return end_; }
86
87protected:
88 Iter begin_, end_;
89};
90
91}
92
93#endif // OPM_ITERATOR_RANGE_HEADER
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:26
Definition: IteratorRange.hpp:31
OPM_HOST_DEVICE bool operator==(const iterator_range_pod< DataType > &rhs) const
Definition: IteratorRange.hpp:37
OPM_HOST_DEVICE const DataType * end() const
Definition: IteratorRange.hpp:43
OPM_HOST_DEVICE iterator_range_pod(const DataType *begin, const DataType *end)
Definition: IteratorRange.hpp:32
OPM_HOST_DEVICE const DataType * begin() const
Definition: IteratorRange.hpp:42
const DataType * begin_
Definition: IteratorRange.hpp:46
OPM_HOST_DEVICE const DataType & operator[](int idx) const
Definition: IteratorRange.hpp:40
OPM_HOST_DEVICE size_t size() const
Definition: IteratorRange.hpp:35
const DataType * end_
Definition: IteratorRange.hpp:47
OPM_HOST_DEVICE bool empty() const
Definition: IteratorRange.hpp:36
Definition: IteratorRange.hpp:52
Iter end_
Definition: IteratorRange.hpp:68
OPM_HOST_DEVICE bool operator==(const iterator_range< Iter > &rhs) const
Definition: IteratorRange.hpp:58
Iter begin_
Definition: IteratorRange.hpp:68
OPM_HOST_DEVICE Iter end() const
Definition: IteratorRange.hpp:65
OPM_HOST_DEVICE Iter begin() const
Definition: IteratorRange.hpp:64
OPM_HOST_DEVICE bool empty() const
Definition: IteratorRange.hpp:57
iterator_range()=default
OPM_HOST_DEVICE size_t size() const
Definition: IteratorRange.hpp:56
OPM_HOST_DEVICE const Iter::value_type & operator[](int idx) const
Definition: IteratorRange.hpp:61
OPM_HOST_DEVICE iterator_range(Iter begin, Iter end)
Definition: IteratorRange.hpp:53
Definition: IteratorRange.hpp:72
Iter begin_
Definition: IteratorRange.hpp:88
OPM_HOST_DEVICE Iter end() const
Definition: IteratorRange.hpp:85
OPM_HOST_DEVICE size_t size() const
Definition: IteratorRange.hpp:76
OPM_HOST_DEVICE bool operator==(const Iter &rhs) const
Definition: IteratorRange.hpp:78
OPM_HOST_DEVICE Iter::value_type & operator[](int idx)
Definition: IteratorRange.hpp:81
OPM_HOST_DEVICE Iter begin() const
Definition: IteratorRange.hpp:84
OPM_HOST_DEVICE bool empty() const
Definition: IteratorRange.hpp:77
Iter end_
Definition: IteratorRange.hpp:88
OPM_HOST_DEVICE mutable_iterator_range(Iter begin, Iter end)
Definition: IteratorRange.hpp:73