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