plugify  1.0.0.0
reference_wrapper.hpp
1 #pragma once
2 
3 #include <type_traits>
4 
5 namespace plugify {
16  template<typename T>
17  class Ref {
18  public:
19  Ref() noexcept : _impl{nullptr} {}
20  Ref(T& impl) noexcept : _impl{std::addressof(impl)} {}
21 
22  Ref(Ref const&) = default;
23  Ref(Ref&&) = default;
24 
25  bool operator==(const Ref& other) const noexcept { return _impl == other._impl; }
26  bool operator==(const T* impl) const noexcept { return _impl == impl; }
27 
28  Ref& operator=(const Ref&) & = default;
29  Ref& operator=(const Ref&) && = delete;
30  Ref& operator=(Ref&&) & = default;
31  Ref& operator=(Ref&&) && = delete;
32 
33  explicit operator bool() const noexcept { return _impl != nullptr; }
34 
35  protected:
36  T* _impl;
37  };
38 
48  template<typename T> static constexpr bool is_ref_v = std::is_standard_layout_v<T> && sizeof(T) == sizeof(void*);
49 }
A lightweight reference wrapper for objects of type T.