WRApplication
External kratos "application" for multiscale time integration.
Range.hpp
Go to the documentation of this file.
1 
3 #pragma once
4 
5 // --- STL Includes ---
6 #include <iterator>
7 #include <type_traits>
8 
9 
10 namespace Kratos::WRApp {
11 
12 
14 
15 
16 #define KRATOS_DEFINE_RANGE(ITERATOR_TYPE, CONST) \
17 { \
18 public: \
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  \
35 private: \
36  ITERATOR_TYPE mBegin; \
37  ITERATOR_TYPE mEnd; \
38 }
39 
40 
42 
43 
44 namespace Detail {
46 template <class T>
47 struct IsConstPointer
48 {};
49 
50 
51 template <class T>
52 struct IsConstPointer<T*>
53 {static constexpr const bool value = false;};
54 
55 
56 template <class T>
57 struct IsConstPointer<const T*>
58 {static constexpr const bool value = true;};
59 
60 
61 template <class TIterator>
62 struct IsConstIterator
63 {
64  static constexpr const bool value = IsConstPointer<typename std::iterator_traits<TIterator>::pointer>::value;
65 };
67 } // namespace Detail
68 
69 
74 
75 
80 template <class TIterator, class IsConstRange = void>
81 class Range
82 KRATOS_DEFINE_RANGE(TIterator, ); // class Range (non-const version)
83 
84 
89 template <class TIterator>
90 class Range<TIterator, typename std::enable_if<Detail::IsConstIterator<TIterator>::value>::type>
91 KRATOS_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