You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think a policy class would be great to allow users to customize how the optional determines if the value is existing. This would allow users to customize this behavior while still using the same unified interface. This is similar to how allocators work in the stl. If its set to void, it can use std::optional behind the scenes instead. could do this by default.
template<typename TYPE, TYPE VALUE>
structValueSentinelfinal
{
boolhas_value(const TYPE& value)
{
return value != VALUE;
}
};
template<typename TYPE, TYPE VALUE>
structGreaterThanSentinelfinal
{
boolhas_value(const TYPE& value)
{
return value > VALUE;
}
};
template<typename TYPE, typename SENTINEL = void>
Markable;
template<typename TYPE, typename SENTINEL>
Markable<TYPE, SENTINEL>
{
// with [[no_unique_address]] the compiler is smart enough to optimize sentinel away if its an empty struct.
[[no_unique_address]] SENTINEL _sentinel;
TYPE _value;
boolhas_value()
{
return _sentinel.has_value(this->_value);
}
};
// specialization for no sentineltemplate<typename TYPE>
Markable<TYPE, void>
{
std::optional<TYPE> value_o = std::nullopt;
boolhas_value()
{
value_o.has_value();
}
};
The text was updated successfully, but these errors were encountered:
I think a policy class would be great to allow users to customize how the optional determines if the value is existing. This would allow users to customize this behavior while still using the same unified interface. This is similar to how allocators work in the stl. If its set to void, it can use std::optional behind the scenes instead. could do this by default.
The text was updated successfully, but these errors were encountered: