Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Ref.h
1 #ifndef GF_REF_H
2 #define GF_REF_H
3 
4 #include <memory>
5 
6 namespace gf {
7 #ifndef DOXYGEN_SHOULD_SKIP_THIS
8 inline namespace v1 {
9 #endif
10 
17  template<typename T>
18  class Ref {
19  public:
25  Ref(T& ref) noexcept
26  : m_ptr(std::addressof(ref))
27  {
28 
29  }
30 
34  Ref(T&&) = delete;
35 
39  Ref(const Ref& other) noexcept = default;
40 
44  Ref& operator=(const Ref& other) noexcept = default;
45 
51  T& get() const noexcept {
52  return *m_ptr;
53  }
54 
60  operator T& () const noexcept {
61  return *m_ptr;
62  }
63 
64  private:
65  T *m_ptr;
66  };
67 
74  template<typename T>
75  constexpr bool operator==(Ref<T> lhs, Ref<T> rhs) noexcept {
76  return std::addressof(lhs.get()) == std::addressof(rhs.get());
77  }
78 
85  template<typename T>
86  constexpr bool operator==(Ref<T> lhs, const T& rhs) noexcept {
87  return std::addressof(lhs.get()) == std::addressof(rhs);
88  }
89 
96  template<typename T>
97  constexpr bool operator==(const T& lhs, Ref<T> rhs) noexcept {
98  return std::addressof(lhs) == std::addressof(rhs.get());
99  }
100 
101 #ifndef DOXYGEN_SHOULD_SKIP_THIS
102 }
103 #endif
104 }
105 
106 #endif // GF_REF_H
constexpr bool operator==(const T &lhs, Ref< T > rhs) noexcept
Referece comparison.
Definition: Ref.h:97
The namespace for gf classes.
Definition: Action.h:35
constexpr bool operator==(Ref< T > lhs, const T &rhs) noexcept
Referece comparison.
Definition: Ref.h:86
constexpr bool operator==(Ref< T > lhs, Ref< T > rhs) noexcept
Referece comparison.
Definition: Ref.h:75
A reference wrapper.
Definition: Ref.h:18
Ref(T &ref) noexcept
Constructor with a lvalue reference.
Definition: Ref.h:25