FTL: Downcast to Optional<T> implicitly
The expression `ftl::Optional(std::optional(T()))` should not have type
`ftl::Optional<std::optional<T>>`.
Bug: 185536303
Test: ftl_test
Change-Id: I931cc58b985e7c41037ed50bc68abdc8028c4bdd
diff --git a/include/ftl/optional.h b/include/ftl/optional.h
index a0a95c4..626507f 100644
--- a/include/ftl/optional.h
+++ b/include/ftl/optional.h
@@ -32,6 +32,9 @@
struct Optional final : std::optional<T> {
using std::optional<T>::optional;
+ // Implicit downcast.
+ Optional(std::optional<T> other) : std::optional<T>(std::move(other)) {}
+
using std::optional<T>::has_value;
using std::optional<T>::value;
@@ -94,8 +97,11 @@
}
};
-// Deduction guide.
+// Deduction guides.
template <typename T>
Optional(T) -> Optional<T>;
+template <typename T>
+Optional(std::optional<T>) -> Optional<T>;
+
} // namespace android::ftl