88
99namespace rfl {
1010
11- // / A smart pointer wrapper that is guaranteed to always contain a valid object with shared ownership.
12- // / The Ref class behaves very similarly to shared_ptr, but unlike shared_ptr,
13- // / it is 100% guaranteed to be filled at all times (unless the user
14- // / tries to access it after calling std::move or does something else that is
15- // / clearly bad practice).
11+ // / A smart pointer wrapper that is guaranteed to always contain a valid object
12+ // / with shared ownership. The Ref class behaves very similarly to shared_ptr,
13+ // / but unlike shared_ptr, it is 100% guaranteed to be filled at all times
14+ // / (unless the user tries to access it after calling std::move or does
15+ // / something else that is clearly bad practice).
1616// / @tparam T The type of object to contain
1717template <class T >
1818class Ref {
1919 public:
20- // / The default way of creating new references is Ref<T>::make(...) or make_ref<T>(...).
21- // / Constructs a new Ref with the given arguments forwarded to T's constructor.
20+ // / The default way of creating new references is Ref<T>::make(...) or
21+ // / make_ref<T>(...). Constructs a new Ref with the given arguments forwarded
22+ // / to T's constructor.
2223 // / @tparam Args Types of constructor arguments
2324 // / @param _args Arguments to forward to T's constructor
2425 // / @return A new Ref containing the constructed object
2526 template <class ... Args>
2627 static Ref<T> make (Args&&... _args) {
27- return Ref<T>(std::make_shared<T>(std::forward<Args>(_args)...));
28+ // Necessary workaround to avoid false positive warning.
29+ auto raw = new T (std::forward<Args>(_args)...);
30+ return Ref<T>(std::shared_ptr<T>(raw));
2831 }
2932
30- // / Creates a Ref from a shared_ptr (move version), returns an Error if the shared_ptr is null.
33+ // / Creates a Ref from a shared_ptr (move version), returns an Error if the
34+ // / shared_ptr is null.
3135 // / @param _ptr The shared_ptr to convert to a Ref
3236 // / @return Result containing the Ref or an error if _ptr is nullptr
3337 static Result<Ref<T>> make (std::shared_ptr<T>&& _ptr) {
@@ -37,7 +41,8 @@ class Ref {
3741 return Ref<T>(std::move (_ptr));
3842 }
3943
40- // / Creates a Ref from a shared_ptr (copy version), returns an Error if the shared_ptr is null.
44+ // / Creates a Ref from a shared_ptr (copy version), returns an Error if the
45+ // / shared_ptr is null.
4146 // / @param _ptr The shared_ptr to convert to a Ref
4247 // / @return Result containing the Ref or an error if _ptr is nullptr
4348 static Result<Ref<T>> make (const std::shared_ptr<T>& _ptr) {
@@ -90,7 +95,8 @@ class Ref {
9095 // / @return Pointer to the contained object
9196 T* operator ->() { return ptr_.get (); }
9297
93- // / Arrow operator (const) - provides access to the underlying object's members.
98+ // / Arrow operator (const) - provides access to the underlying object's
99+ // / members.
94100 // / @return Const pointer to the contained object
95101 T* operator ->() const { return ptr_.get (); }
96102
0 commit comments