22 #ifndef WXMAXIMA_CACHEDVALUE_H
23 #define WXMAXIMA_CACHEDVALUE_H
33 #include <type_traits>
43 template <typename T, typename std::enable_if<std::is_integral<T>::value,
bool>::type =
true>
46 static constexpr T invalid = std::numeric_limits<T>::max();
47 mutable T m_value = invalid;
53 constexpr
bool IsValid()
const {
return m_value != invalid; }
54 constexpr
bool IsInvalid()
const {
return m_value == invalid; }
55 constexpr
void Invalidate() { m_value = invalid; }
56 operator T()
const {
return Get(); }
59 wxASSERT_MSG(m_value != invalid,
"Attempted to use an invalid cached value");
60 return (m_value != invalid) ? m_value : T{};
62 void SetCached(T newValue)
const
64 wxASSERT_MSG(newValue != invalid,
"Attempted to set an out-of-range cached value.");