Created on 2025-07-25.00:00:00 last changed 1 month ago
Proposed resolution:
This wording is relative to N5014.
Modify [optional.optional.ref.general], header <iterator> synopsis, as indicated:
namespace std { template<class T> class optional<T&> { […] constexpr T& value() const; // freestanding-deleted template<class U = remove_cv_t<T>> constexpr remove_cv_t<T> value_or(U&& u) const; // not always present […] }; }
Modify [optional.ref.observe] as indicated:
template<class U = remove_cv_t<T>> constexpr remove_cv_t<T> value_or(U&& u) const;-8- Let `X` be remove_cv_t<T>.
-9- Mandates: is_constructible_v<X, T&> && is_convertible_v<U, X> is `true`. -10- Effects: Equivalent to:return has_value() ? *val : static_cast<X>(std::forward<U>(u));-?- Remarks: This function template is present if and only if `T` is a non-array object type.
Currently, if `T` is an array type or a function type, instantiation of std::optional<T&> is still ill-formed, because the return type of its `value_or` member function is specified as remove_cv_t<T>, which is invalid as a return type.
However, we don't exclude such T& from valid contained types. Given only `value_or` is problematic here, perhaps we can avoid providing it if `T` is not returnable.History | |||
---|---|---|---|
Date | User | Action | Args |
2025-07-27 09:18:00 | admin | set | messages: + msg14916 |
2025-07-25 00:00:00 | admin | create |