Add non-empty assertion to Option's deref op

This commit is contained in:
Martin Hořeňovský 2021-10-05 19:22:22 +02:00
parent 48a889859b
commit c6c46a168f
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
1 changed files with 16 additions and 4 deletions

View File

@ -46,10 +46,22 @@ namespace Catch {
nullableValue = nullptr;
}
T& operator*() { return *nullableValue; }
T const& operator*() const { return *nullableValue; }
T* operator->() { return nullableValue; }
const T* operator->() const { return nullableValue; }
T& operator*() {
assert(nullableValue);
return *nullableValue;
}
T const& operator*() const {
assert(nullableValue);
return *nullableValue;
}
T* operator->() {
assert(nullableValue);
return nullableValue;
}
const T* operator->() const {
assert(nullableValue);
return nullableValue;
}
T valueOr( T const& defaultValue ) const {
return nullableValue ? *nullableValue : defaultValue;