WRApplication
External kratos "application" for multiscale time integration.
All Classes Namespaces Files Functions Variables Typedefs Friends Macros Modules Pages
MapKeyRange.hpp
Go to the documentation of this file.
1
2
3#pragma once
4
5// --- Core Includes ---
6#include "includes/kratos_export_api.h"
7
8// --- WRApp Includes ---
10
11// --- STL Includes ---
12#include <type_traits>
13
14
15namespace Kratos::WRApp {
16
17
22
23
28template <class TIterator>
29class KRATOS_API(WR_APPLICATION) MapKeyIterator
30{
31public:
32 using value_type = typename TIterator::value_type::first_type;
33
35 using pointer = typename std::conditional<Detail::IsConstIterator<TIterator>::value,const value_type*,value_type*>::type;
36
38 using reference = typename std::conditional<Detail::IsConstIterator<TIterator>::value,const value_type&,value_type&>::type;
39
40 using difference_type = typename TIterator::difference_type;
41
42 using iterator_category = std::forward_iterator_tag;
43
44 MapKeyIterator() = default;
45
46 MapKeyIterator(TIterator Wrapped)
47 : mWrapped(Wrapped)
48 {}
49
50 MapKeyIterator(MapKeyIterator&& rOther) noexcept = default;
51
52 MapKeyIterator(const MapKeyIterator& rOther) noexcept = default;
53
55 {return mWrapped->first;}
56
58 {return &mWrapped->first;}
59
61 {++mWrapped; return *this;}
62
64 {MapKeyIterator copy(*this); ++(*this); return copy;}
65
66 friend bool operator==(MapKeyIterator Left, MapKeyIterator Right)
67 {return Left.mWrapped == Right.mWrapped;}
68
69 friend bool operator!=(MapKeyIterator Left, MapKeyIterator Right)
70 {return !(Left == Right);}
71
72private:
73 TIterator mWrapped;
74}; // class MapKeyIterator
75
76
77
81template <class TMap>
82using MapKeyRange = Range<MapKeyIterator<typename TMap::const_iterator>>;
83
84
89template <class TMap>
90MapKeyRange<TMap> KRATOS_API(WR_APPLICATION) MakeConstMapKeyRange(const TMap& rMap)
91{
92 return Range<MapKeyIterator<typename TMap::const_iterator>>(rMap.begin(), rMap.end());
93}
94
95
98
99
100} // namespace Kratos::WRApp
Iterator providing access to the keys of an std::map or std::unordered_map.
Definition MapKeyRange.hpp:30
MapKeyIterator(MapKeyIterator &&rOther) noexcept=default
typename std::conditional< Detail::IsConstIterator< TIterator >::value, const value_type *, value_type * >::type pointer
const key_type* if const_iterator else key_type*
Definition MapKeyRange.hpp:35
pointer operator->()
Definition MapKeyRange.hpp:57
typename TIterator::value_type::first_type value_type
Definition MapKeyRange.hpp:32
friend bool operator!=(MapKeyIterator Left, MapKeyIterator Right)
Definition MapKeyRange.hpp:69
reference operator*()
Definition MapKeyRange.hpp:54
typename std::conditional< Detail::IsConstIterator< TIterator >::value, const value_type &, value_type & >::type reference
const key_type& if const_iterator else key_type&
Definition MapKeyRange.hpp:38
typename TIterator::difference_type difference_type
Definition MapKeyRange.hpp:40
MapKeyIterator & operator++()
Definition MapKeyRange.hpp:60
std::forward_iterator_tag iterator_category
Definition MapKeyRange.hpp:42
MapKeyIterator operator++(int)
Definition MapKeyRange.hpp:63
MapKeyIterator(TIterator Wrapped)
Definition MapKeyRange.hpp:46
MapKeyIterator(const MapKeyIterator &rOther) noexcept=default
friend bool operator==(MapKeyIterator Left, MapKeyIterator Right)
Definition MapKeyRange.hpp:66
Range< MapKeyIterator< typename TMap::const_iterator > > MapKeyRange
Range class iterating over the keys of a standard-conforming map type.
Definition MapKeyRange.hpp:82
Definition MPIUtils.hpp:9