Implements assignment, some tweaks for borrowed_ptr.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-05-26 13:44:06 +02:00
parent 817b4c55d8
commit a84c7ae45c
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 8 additions and 3 deletions

View File

@ -10,20 +10,25 @@ private:
T* _raw; T* _raw;
public: public:
inline borrowed_ptr<T>() : _raw(nullptr){};
inline borrowed_ptr<T>(T* ptr) : _raw(ptr){}; inline borrowed_ptr<T>(T* ptr) : _raw(ptr){};
inline borrowed_ptr(const borrowed_ptr<T>& other) : _raw(other._raw){}; inline borrowed_ptr(const borrowed_ptr<T>& other) : _raw(other._raw){};
inline borrowed_ptr(const std::unique_ptr<T>& other) : _raw(other.get()){}; inline borrowed_ptr(const std::unique_ptr<T>& other) : _raw(other.get()){};
~borrowed_ptr() = default; ~borrowed_ptr() = default;
inline T* operator->() noexcept { return _raw; } inline borrowed_ptr<T>& operator=(const borrowed_ptr<T>& rhs) {
inline const T* operator->() const noexcept { return _raw; } _raw = rhs._raw;
return *this;
}
inline T* operator->() noexcept { return _raw; }
inline T* GetRaw() noexcept { return _raw; } inline T* GetRaw() noexcept { return _raw; }
inline const T* GetRaw() const noexcept { return _raw; }
inline bool operator==(const borrowed_ptr& rhs) const { return _raw == rhs._raw; } inline bool operator==(const borrowed_ptr& rhs) const { return _raw == rhs._raw; }
inline bool operator!=(const borrowed_ptr& rhs) const { return _raw != rhs._raw; } inline bool operator!=(const borrowed_ptr& rhs) const { return _raw != rhs._raw; }
[[nodiscard]] inline constexpr bool IsNull() const noexcept { return _raw == nullptr; }
}; };
#endif // ARBUTILS_BORROWED_PTR_HPP #endif // ARBUTILS_BORROWED_PTR_HPP