1 #ifndef LIBFILEZILLA_SHARED_HEADER
2 #define LIBFILEZILLA_SHARED_HEADER
27 shared_optional() noexcept(!Init || std::is_nothrow_constructible_v<T>);
42 const T& operator*()
const;
43 const T* operator->()
const;
56 bool operator<(T
const& cmp)
const;
62 inline bool operator!=(T
const& cmp)
const {
return !(*
this == cmp); }
68 explicit operator bool()
const {
return static_cast<bool>(data_); }
70 bool empty()
const {
return !data_; }
72 std::shared_ptr<T> data_;
87 : data_(Init ? std::make_shared<T>() :
nullptr)
91 template<
typename T,
bool Init> shared_optional<T, Init>::shared_optional(
const T& v)
92 : data_(std::make_shared<T>(v))
98 if (data_ == cmp.data_) {
101 else if (!Init && (!data_ || !cmp.data_)) {
105 return *data_ == *cmp.data_;
110 if (!Init && !data_) {
113 return *data_ == cmp;
118 return data_ == cmp.data_;
123 if (!Init && !data_) {
124 data_ = std::make_shared<T>();
126 if (data_.use_count() > 1) {
127 data_ = std::make_shared<T>(*data_);
135 if (data_ == cmp.data_) {
138 else if (!Init && !data_) {
139 return static_cast<bool>(cmp.data_);
141 else if (!Init && !cmp.data_) {
144 return *data_ < *cmp.data_;
147 template<
typename T,
bool Init>
bool shared_optional<T, Init>::operator<(T
const& cmp)
const
149 if (!Init && !data_) {
155 template<
typename T,
bool Init>
void shared_optional<T, Init>::clear()
160 else if (data_.use_count() <= 1) {
164 data_ = std::make_shared<T>();
168 template<
typename T,
bool Init>
const T& shared_optional<T, Init>::operator*()
const
173 template<
typename T,
bool Init>
const T* shared_optional<T, Init>::operator->()
const
shared_optional is like std::shared_ptr but with relational operators acting like C++17's std::option...
Definition: shared.hpp:25
bool is_same(shared_optional< T, Init > const &cmp) const
Only compares the pointers.
Definition: shared.hpp:116
T & get()
Gets a reference to the stored object.
Definition: shared.hpp:121
The namespace used by libfilezilla.
Definition: apply.hpp:17
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.