Add Optional::value_or_compute for lazy computation of default value
This commit is contained in:
parent
8a6a76fcd3
commit
56ee329d79
|
@ -84,6 +84,9 @@ public:
|
||||||
template<typename U>
|
template<typename U>
|
||||||
T value_or(U&& fallback) const { return m_valid ? m_value : T{std::forward<U>(fallback)}; }
|
T value_or(U&& fallback) const { return m_valid ? m_value : T{std::forward<U>(fallback)}; }
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
T value_or_compute(U&& compute_func) const { return m_valid ? m_value : compute_func(); }
|
||||||
|
|
||||||
void reset() { destruct_ifn(); m_valid = false; }
|
void reset() { destruct_ifn(); m_valid = false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user