mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
AK: Bring back FixedArray<T>
Let's bring this class back, but without the confusing resize() API. A FixedArray<T> is simply a fixed-size array of T. The size is provided at run-time, unlike Array<T> where the size is provided at compile-time.
This commit is contained in:
parent
846685fca2
commit
88c8451973
4 changed files with 145 additions and 0 deletions
29
Tests/AK/TestFixedArray.cpp
Normal file
29
Tests/AK/TestFixedArray.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestSuite.h>
|
||||
|
||||
#include <AK/FixedArray.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
TEST_CASE(construct)
|
||||
{
|
||||
EXPECT(FixedArray<int>().size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE(ints)
|
||||
{
|
||||
FixedArray<int> ints(3);
|
||||
ints[0] = 0;
|
||||
ints[1] = 1;
|
||||
ints[2] = 2;
|
||||
EXPECT_EQ(ints[0], 0);
|
||||
EXPECT_EQ(ints[1], 1);
|
||||
EXPECT_EQ(ints[2], 2);
|
||||
|
||||
ints.clear();
|
||||
EXPECT_EQ(ints.size(), 0u);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue