std::optional
has the method
template< class U > constexpr T value_or( U&& default_value ) const&;
and yet, it doesn't have the constructor
template< class U > optional(bool condition, const U& value );
which seeps like the opposite thing. Alternatively, you would expect it to have the static method / named constructor idiom:
constexpr std::optional<T> value_if(bool condition, const T& value) {
return condition ? nullopt : std::optional(value);
}
My questions:
- Is there a conceptual problem with a
value_if
(in either of the variants I listed)? - Was something like that proposed to go into the standard?
Note: I wasn't sure whether to have const T& value
or const T&& value
.