optional: Remove the value() method that returns non-const-ref.
I'm not convinced that `opt.value() = foo` is a desirable pattern, and worse still it confuses some compilers about which overload to use. Just remove it.
This commit is contained in:
parent
ced82a0501
commit
4abe43c131
@ -50,7 +50,6 @@ class optional {
|
||||
|
||||
// value() returns the contained value, or defaultValue if the optional does
|
||||
// not contain a value.
|
||||
inline T& value(const T& defaultValue);
|
||||
inline const T& value(const T& defaultValue) const;
|
||||
|
||||
// operator bool() returns true if the optional contains a value.
|
||||
@ -119,14 +118,6 @@ const T& optional<T>::value() const {
|
||||
return val;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& optional<T>::value(const T& defaultValue) {
|
||||
if (!has_value()) {
|
||||
return defaultValue;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& optional<T>::value(const T& defaultValue) const {
|
||||
if (!has_value()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user