WRApplication
External kratos "application" for multiscale time integration.
Loading...
Searching...
No Matches
Range.hpp
Go to the documentation of this file.
1
2
3#pragma once
4
5// --- STL Includes ---
6#include <iterator>
7#include <type_traits>
8
9
10namespace Kratos::WRApp {
11
12
14
15
16#define KRATOS_DEFINE_RANGE(ITERATOR_TYPE, CONST) \
17{ \
18public: \
19 using value_type = typename std::iterator_traits<TIterator>::value_type; \
20 using pointer = typename std::iterator_traits<TIterator>::pointer; \
21 using reference = typename std::iterator_traits<TIterator>::reference; \
22 using size_type = std::size_t; \
23 \
24 Range() : mBegin(), mEnd() {} \
25 Range(ITERATOR_TYPE begin, ITERATOR_TYPE end) \
26 : mBegin(begin), mEnd(end) {} \
27 Range(Range&& rOther) noexcept = default; \
28 Range(const Range& rOther) noexcept = default; \
29 \
30 ITERATOR_TYPE begin() CONST noexcept {return mBegin;} \
31 ITERATOR_TYPE end() CONST noexcept {return mEnd;} \
32 size_type size() const noexcept {return std::distance(mBegin, mEnd);} \
33 bool empty() const noexcept {return mBegin == mEnd;} \
34 \
35private: \
36 ITERATOR_TYPE mBegin; \
37 ITERATOR_TYPE mEnd; \
38}
39
40
42
43
44namespace Detail {
46template <class T>
47struct IsConstPointer
48{};
49
50
51template <class T>
52struct IsConstPointer<T*>
53{static constexpr const bool value = false;};
54
55
56template <class T>
57struct IsConstPointer<const T*>
58{static constexpr const bool value = true;};
59
60
61template <class TIterator>
62struct IsConstIterator
63{
64 static constexpr const bool value = IsConstPointer<typename std::iterator_traits<TIterator>::pointer>::value;
65};
67} // namespace Detail
68
69
74
75
80template <class TIterator, class IsConstRange = void>
81class Range
82KRATOS_DEFINE_RANGE(TIterator, ); // class Range (non-const version)
83
84
89template <class TIterator>
90class Range<TIterator, typename std::enable_if<Detail::IsConstIterator<TIterator>::value>::type>
91KRATOS_DEFINE_RANGE(TIterator, const); // class Range (const version)
92
93
96
97
98#undef KRATOS_DEFINE_RANGE
99
100
101} // namespace Kratos::WRApp
class Range KRATOS_DEFINE_RANGE(TIterator,)
Class representing a view into a subrange of a container.
Definition MPIUtils.hpp:9
Definition CheckpointID.hpp:68