mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 11:47:04 +08:00
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:
parent
494f10a5a8
commit
5dbffa8b6d
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user