mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
AK: Add operator* and operator-> overloads in Optional.
This commit is contained in:
parent
c770b0bbec
commit
a7c014125f
2 changed files with 14 additions and 0 deletions
|
@ -155,6 +155,12 @@ public:
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const T& operator*() const { return value(); }
|
||||||
|
T& operator*() { return value(); }
|
||||||
|
|
||||||
|
const T* operator->() const { return &value(); }
|
||||||
|
T* operator->() { return &value(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Call when we don't want to alter the consume state
|
// Call when we don't want to alter the consume state
|
||||||
ALWAYS_INLINE const T& value_without_consume_state() const
|
ALWAYS_INLINE const T& value_without_consume_state() const
|
||||||
|
|
|
@ -66,4 +66,12 @@ TEST_CASE(optional_leak_1)
|
||||||
EXPECT_EQ(vec[0].str.value(), "foo");
|
EXPECT_EQ(vec[0].str.value(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(short_notation)
|
||||||
|
{
|
||||||
|
Optional<StringView> value = "foo";
|
||||||
|
|
||||||
|
EXPECT_EQ(value->length(), 3u);
|
||||||
|
EXPECT_EQ(*value, "foo");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_MAIN(Optional)
|
TEST_MAIN(Optional)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue