esphome::optional: implement direct-initializing constructor

This allows code generator to pass e.g. string literals for functions with
optional<std::string> arguments.
This commit is contained in:
Tomasz Wasilczyk 2024-05-05 20:06:46 -07:00
parent 243469ad7c
commit ef7cfacc33
1 changed files with 2 additions and 0 deletions

View File

@ -48,6 +48,8 @@ template<typename T> class optional { // NOLINT
template<class U> optional(optional<U> const &other) : has_value_(other.has_value()), value_(other.value()) {}
template<class U = T> constexpr optional(U &&value) : has_value_(true), value_(std::forward<U>(value)) {}
optional &operator=(nullopt_t) {
reset();
return *this;