mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Fixes PS::StaticVector insert and adds more tests
There was an incorrect mutable iterator construction missed in
ca242239f1.
This commit is contained in:
parent
ea5a350f83
commit
9306aae297
2 changed files with 30 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<int, 20>{0, 1, 2, 3} != PS::StaticVector<int, 20>{3, 2, 1, 0}));
|
||||
}
|
||||
|
||||
void test_resize()
|
||||
{
|
||||
size_t count{0};
|
||||
|
||||
{
|
||||
PS::StaticVector<ConstructionCounter, 8> 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<decltype(std::declval<PS::StaticVector<int, 1>>().begin()), int*>);
|
||||
static_assert(std::is_same_v<decltype(std::declval<const PS::StaticVector<int, 1>>().begin()),
|
||||
|
|
|
|||
Loading…
Reference in a new issue