Scorum
ref.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <memory>
3 
4 namespace scorum {
5 namespace utils {
6 
7 /*
8  * std::reference_wrapper has special semantics in template argument deduction rules so it doesn't work properly with
9  * fc::static_variant.
10  *
11  * Using custom 'utils::ref' type instead which doesn't have such semantics
12  */
13 template <typename T> class ref
14 {
15 public:
16  // We need default ctor because of the fc::static_variant's visitor
17  ref() = default;
18  ref(T& inst)
19  : _inst(std::addressof(inst))
20  {
21  }
22  ref(const ref&) = default;
23  ref(ref&&) = default;
24  ref& operator=(const ref&) = default;
25  ref& operator=(ref&&) = default;
26 
27  operator T&() const
28  {
29  return *_inst;
30  }
31 
32  T& get() const
33  {
34  return *_inst;
35  }
36 
37 private:
38  T* _inst;
39 };
40 
41 template <typename U> ref<U> make_ref(U& r)
42 {
43  return ref<U>(r);
44 }
45 }
46 }
ref(ref &&)=default
T & get() const
Definition: ref.hpp:32
ref(const ref &)=default
ref & operator=(ref &&)=default
ref & operator=(const ref &)=default
ref(T &inst)
Definition: ref.hpp:18
ref< U > make_ref(U &r)
Definition: ref.hpp:41
Definition: asset.cpp:15