Add Optional::value_or_compute for lazy computation of default value

This commit is contained in:
Maxime Coste 2019-01-03 22:49:40 +11:00
parent 8a6a76fcd3
commit 56ee329d79

View File

@ -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: