15#ifndef LIEF_CAN_BE_UNIQUE_H
16#define LIEF_CAN_BE_UNIQUE_H
36 ptr_(std::exchange(other.ptr_,
nullptr)),
37 owned_(std::exchange(other.owned_,
false)) {}
41 std::swap(ptr_, tmp.ptr_);
42 std::swap(owned_, tmp.owned_);
47 ptr_(std::addressof(ptr)) {}
50 ptr_(const_cast<T*>(std::addressof(ptr))) {}
55 ptr_(unique_ptr.release()),
71 std::unique_ptr<T>
result(ptr_);
77 const T*
get()
const {
98 T* ptr = std::exchange(ptr_,
nullptr);
99 if (std::exchange(owned_,
false)) {
100 std::default_delete<T>()(ptr);
104 explicit operator bool()
const {
105 return ptr_ !=
nullptr;
129 return static_cast<bool>(lhs);
134 return static_cast<bool>(lhs);
Definition canbe_unique.hpp:24
~canbe_unique()
Definition canbe_unique.hpp:108
canbe_unique(const T &&)=delete
canbe_unique & operator=(std::nullptr_t)
Definition canbe_unique.hpp:30
T * operator->()
Definition canbe_unique.hpp:81
void reset()
Definition canbe_unique.hpp:97
const T & operator*() const
Definition canbe_unique.hpp:93
T & operator*()
Definition canbe_unique.hpp:89
const T * operator->() const
Definition canbe_unique.hpp:85
canbe_unique & operator=(canbe_unique &&other) noexcept
Definition canbe_unique.hpp:39
bool is_owned() const
Definition canbe_unique.hpp:62
std::unique_ptr< T > take_ownership()
Definition canbe_unique.hpp:66
const T * get() const
Definition canbe_unique.hpp:77
canbe_unique(const canbe_unique &)=delete
canbe_unique(T &ptr)
Definition canbe_unique.hpp:46
canbe_unique(canbe_unique &&other) noexcept
Definition canbe_unique.hpp:35
canbe_unique(std::unique_ptr< T > unique_ptr)
Definition canbe_unique.hpp:54
canbe_unique & operator=(const canbe_unique &)=delete
canbe_unique(const T &ptr)
Definition canbe_unique.hpp:49
T * get()
Definition canbe_unique.hpp:58
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
Definition Abstract/DebugInfo.hpp:27
bool operator!=(const canbe_unique< T > &lhs, std::nullptr_t)
Definition canbe_unique.hpp:128
bool operator==(const canbe_unique< T > &lhs, std::nullptr_t)
Definition canbe_unique.hpp:118