mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
[core] Restore = delete for stateful lambdas in TemplatableFn
This commit is contained in:
@@ -54,6 +54,9 @@ template<typename T, typename... X> class TemplatableFn {
|
||||
std::invocable<F, X...> &&std::convertible_to<std::invoke_result_t<F, X...>, T> &&std::is_empty_v<F>
|
||||
&&std::default_initializable<F> : f_([](X... x) -> T { return static_cast<T>(F{}(x...)); }) {}
|
||||
|
||||
// Reject stateful lambdas (non-empty, i.e. capturing) with a clear error
|
||||
template<typename F> TemplatableFn(F) requires std::invocable<F, X...> &&(!std::is_empty_v<F>) = delete;
|
||||
|
||||
bool has_value() const { return this->f_ != nullptr; }
|
||||
|
||||
T value(X... x) const { return this->f_ ? this->f_(x...) : T{}; }
|
||||
|
||||
Reference in New Issue
Block a user