mirror of
https://github.com/esphome/esphome.git
synced 2026-09-25 14:00:25 +00:00
The custom optional implementation (from optional-bare, 2017) predates C++17. All ESPHome platforms now compile with gnu++20, making std::optional available everywhere. The custom implementation had several issues: - No emplace() support - Always default-constructs value_ (wasteful for non-trivial types) - reset() only flips a bool without destroying the value - No move semantics - Requires T to be default constructible Replace with using aliases (using std::optional, using std::nullopt, etc.) so all existing code using esphome::optional continues to work. Also fix ~30 unsafe .value() calls across climate IR components that relied on the custom optional's behavior of returning a default-constructed value when empty. With std::optional, accessing an empty optional is UB. These are replaced with value_or() using appropriate defaults (CLIMATE_FAN_AUTO, CLIMATE_PRESET_NONE).
13 lines
170 B
C++
13 lines
170 B
C++
#pragma once
|
|
|
|
#include <optional>
|
|
|
|
namespace esphome {
|
|
|
|
using std::make_optional;
|
|
using std::nullopt;
|
|
using std::nullopt_t;
|
|
using std::optional;
|
|
|
|
} // namespace esphome
|