1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:37:35 +00:00

AK: Add HashMap(std::initializer_list<Entry>) constructor

This allows us to construct a HashMap from an initializer list like so:

    HashMap<K, V> hash_map = { { K, V }, { K, V } { K, V } };
This commit is contained in:
Linus Groh 2020-12-28 12:49:16 +01:00 committed by Andreas Kling
parent 1dbd264239
commit 1ed72cc580
2 changed files with 31 additions and 1 deletions

View file

@ -36,6 +36,17 @@ TEST_CASE(construct)
EXPECT_EQ(IntIntMap().size(), 0u);
}
TEST_CASE(construct_from_initializer_list)
{
HashMap<int, String> number_to_string {
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
};
EXPECT_EQ(number_to_string.is_empty(), false);
EXPECT_EQ(number_to_string.size(), 3u);
}
TEST_CASE(populate)
{
HashMap<int, String> number_to_string;