mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
AK: Make HashMap::try_ensure work with a fallible construction callback
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
This commit is contained in:
parent
2f4a83215c
commit
44de4d163b
1 changed files with 7 additions and 2 deletions
|
@ -228,8 +228,13 @@ public:
|
||||||
auto it = find(key);
|
auto it = find(key);
|
||||||
if (it != end())
|
if (it != end())
|
||||||
return it->value;
|
return it->value;
|
||||||
|
if constexpr (FallibleFunction<Callback>) {
|
||||||
|
auto result = TRY(try_set(key, TRY(initialization_callback())));
|
||||||
|
VERIFY(result == HashSetResult::InsertedNewEntry);
|
||||||
|
} else {
|
||||||
auto result = TRY(try_set(key, initialization_callback()));
|
auto result = TRY(try_set(key, initialization_callback()));
|
||||||
VERIFY(result == HashSetResult::InsertedNewEntry);
|
VERIFY(result == HashSetResult::InsertedNewEntry);
|
||||||
|
}
|
||||||
return find(key)->value;
|
return find(key)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue