diff --git a/source/ps/containers/StaticVector.h b/source/ps/containers/StaticVector.h index 0583303411..eb52e4d1c9 100644 --- a/source/ps/containers/StaticVector.h +++ b/source/ps/containers/StaticVector.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -418,7 +418,7 @@ public: new(end()) T{std::move(back())}; ++m_Size; - const iterator mutableLocation{MutableIter(location)}; + const iterator mutableLocation{MakeMutableIterator(location)}; std::move_backward(mutableLocation, std::prev(end(), 2), std::prev(end(), 1)); *mutableLocation = value; diff --git a/source/ps/containers/tests/test_StaticVector.h b/source/ps/containers/tests/test_StaticVector.h index dd14bf4efa..de89d6f906 100644 --- a/source/ps/containers/tests/test_StaticVector.h +++ b/source/ps/containers/tests/test_StaticVector.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -104,6 +104,12 @@ public: vec.emplace_back(count); vec.insert(vec.begin(), ConstructionCounter{count}); TS_ASSERT_EQUALS(count, 2); + + { + ConstructionCounter lval{count}; + vec.insert(vec.begin(), lval); + } + TS_ASSERT_EQUALS(count, 3); } TS_ASSERT_EQUALS(count, 0); @@ -192,6 +198,27 @@ public: TS_ASSERT((PS::StaticVector{0, 1, 2, 3} != PS::StaticVector{3, 2, 1, 0})); } + void test_resize() + { + size_t count{0}; + + { + PS::StaticVector vec{}; + + vec.resize(4, ConstructionCounter{count}); + + TS_ASSERT_EQUALS(count, 4); + + { + ConstructionCounter lval{count}; + vec.resize(8, lval); + } + TS_ASSERT_EQUALS(count, 8); + } + + TS_ASSERT_EQUALS(count, 0); + } + // Types static_assert(std::is_same_v>().begin()), int*>); static_assert(std::is_same_v>().begin()),