mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add operator* and operator-> overloads in Optional.
This commit is contained in:
parent
c770b0bbec
commit
a7c014125f
Notes:
sideshowbarker
2024-07-19 00:19:46 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/a7c014125fc Pull-request: https://github.com/SerenityOS/serenity/pull/4669
2 changed files with 14 additions and 0 deletions
|
@ -155,6 +155,12 @@ public:
|
|||
return fallback;
|
||||
}
|
||||
|
||||
const T& operator*() const { return value(); }
|
||||
T& operator*() { return value(); }
|
||||
|
||||
const T* operator->() const { return &value(); }
|
||||
T* operator->() { return &value(); }
|
||||
|
||||
private:
|
||||
// Call when we don't want to alter the consume state
|
||||
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");
|
||||
}
|
||||
|
||||
TEST_CASE(short_notation)
|
||||
{
|
||||
Optional<StringView> value = "foo";
|
||||
|
||||
EXPECT_EQ(value->length(), 3u);
|
||||
EXPECT_EQ(*value, "foo");
|
||||
}
|
||||
|
||||
TEST_MAIN(Optional)
|
||||
|
|
Loading…
Reference in a new issue