diff --git a/tdutils/td/utils/optional.h b/tdutils/td/utils/optional.h index b498db840..55c95f4ff 100644 --- a/tdutils/td/utils/optional.h +++ b/tdutils/td/utils/optional.h @@ -13,7 +13,7 @@ namespace td { -template +template ::value> class optional { public: optional() = default; @@ -22,6 +22,25 @@ class optional { int> = 0> optional(T1 &&t) : impl_(std::forward(t)) { } + + optional(const optional &other) { + if (other) { + impl_ = Result(other.value()); + } + } + + optional &operator=(const optional &other) { + if (other) { + impl_ = Result(other.value()); + } else { + impl_ = Result(); + } + } + + optional(optional &&other) = default; + optional &operator=(optional &&other) = default; + ~optional() = default; + explicit operator bool() const { return impl_.is_ok(); } @@ -39,4 +58,17 @@ class optional { Result impl_; }; +template +struct optional : optional { + optional() = default; + + using optional::optional; + + optional(const optional &other) = delete; + optional &operator=(const optional &other) = delete; + optional(optional &&) = default; + optional &operator=(optional &&) = default; + ~optional() = default; +}; + } // namespace td