SPH
PerElementWrapper.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include "objects/Object.h"
7 
9 
10 template <typename TContainer>
12 private:
13  TContainer&& container;
14 
15  using RawType = std::decay_t<TContainer>;
16 
17 public:
18  PerElementWrapper(TContainer&& container)
19  : container(std::forward<TContainer>(container)) {}
20 
21  template <typename TValue>
22  bool operator==(const TValue& value) const {
23  const typename RawType::Type t2 = value;
24  for (const auto& t1 : container) {
25  if (t1 != t2) {
26  return false;
27  }
28  }
29  return true;
30  }
31 
32  template <typename TValue>
33  bool operator!=(const TValue& value) const {
34  return !(*this == value);
35  }
36 
37  template <typename TValue>
38  bool operator>(const TValue& value) const {
39  const typename RawType::Type t2 = value;
40  for (const auto& t1 : container) {
41  if (t1 <= t2) {
42  return false;
43  }
44  }
45  return true;
46  }
47 
48  template <typename TValue>
49  bool operator>=(const TValue& value) const {
50  const typename RawType::Type t2 = value;
51  for (const auto& t1 : container) {
52  if (t1 < t2) {
53  return false;
54  }
55  }
56  return true;
57  }
58 
59  template <typename TValue>
60  bool operator<(const TValue& value) const {
61  return !(*this >= value);
62  }
63 
64  template <typename TValue>
65  bool operator<=(const TValue& value) const {
66  return !(*this > value);
67  }
68 
69  friend std::ostream& operator<<(std::ostream& stream, const PerElementWrapper& wrapper) {
70  stream << wrapper.container;
71  return stream;
72  }
73 };
74 
75 template <typename TContainer>
76 PerElementWrapper<TContainer> perElement(TContainer&& container) {
77  return PerElementWrapper<TContainer>(std::forward<TContainer>(container));
78 }
79 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Common macros and basic objects.
#define NAMESPACE_SPH_END
Definition: Object.h:12
PerElementWrapper< TContainer > perElement(TContainer &&container)
bool operator==(const TValue &value) const
bool operator<(const TValue &value) const
friend std::ostream & operator<<(std::ostream &stream, const PerElementWrapper &wrapper)
PerElementWrapper(TContainer &&container)
bool operator!=(const TValue &value) const
bool operator>(const TValue &value) const
bool operator<=(const TValue &value) const
bool operator>=(const TValue &value) const
Overload of std::swap for Sph::Array.
Definition: Array.h:578