Add a maybe_t constructor taking std::unique_ptr

CXX does not allow generic types like maybe_t.  When porting a C++ function
that returns maybe_t to Rust, we return std::unique_ptr instead. Let's make
the transition more seamless by allowing to convert back to maybe_t implicitly.
This commit is contained in:
Johannes Altmanninger 2023-03-04 03:19:44 +01:00
parent 494f10a5a8
commit 5dbffa8b6d

View File

@ -2,6 +2,7 @@
#define FISH_MAYBE_H
#include <cassert>
#include <memory>
#include <new>
#include <type_traits>
#include <utility>
@ -193,6 +194,10 @@ class maybe_t : private maybe_detail::conditionally_copyable_t<T> {
maybe_t(const maybe_t &) = default;
maybe_t(maybe_t &&) = default;
/* implicit */ maybe_t(std::unique_ptr<T> v) : maybe_t() {
if (v) *this = std::move(*v);
}
// Construct a value in-place.
template <class... Args>
void emplace(Args &&...args) {