Skip to content

Commit 820fed5

Browse files
authored
Make vector<bool> work again (#703)
1 parent 95c342e commit 820fed5

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

strings/base_collections_base.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,17 @@ namespace winrt::impl
6060
struct removed_value
6161
{
6262
// Trivially destructible; okay to run destructor under lock
63-
void assign(T&) {}
63+
template <typename U>
64+
void assign(U&&) {}
6465
};
6566

6667
template <typename T>
6768
struct removed_value<T, std::enable_if_t<std::is_move_constructible_v<T> && !std::is_trivially_destructible_v<T>>>
6869
{
6970
std::optional<T> m_value;
7071

71-
void assign(T& value)
72+
template <typename U>
73+
void assign(U&& value)
7274
{
7375
m_value.emplace(std::move(value));
7476
}
@@ -313,7 +315,7 @@ WINRT_EXPORT namespace winrt
313315
}
314316

315317
this->increment_version();
316-
auto& pos = static_cast<D&>(*this).get_container()[index];
318+
auto&& pos = static_cast<D&>(*this).get_container()[index];
317319
oldValue.assign(pos);
318320
pos = static_cast<D const&>(*this).wrap_value(value);
319321
}

test/old_tests/UnitTests/single_threaded_vector.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,33 @@ TEST_CASE("test_single_threaded_vector")
110110
test_vector(single_threaded_vector<int>());
111111
test_vector(single_threaded_observable_vector<int>());
112112
}
113+
114+
TEST_CASE("single_threaded_vector of bool")
115+
{
116+
auto values = single_threaded_vector<bool>();
117+
values.Append(true);
118+
values.ReplaceAll({ false, true, false, true });
119+
values.InsertAt(1, false);
120+
values.SetAt(2, false);
121+
REQUIRE(values.Size() == 5);
122+
REQUIRE(!values.GetAt(0));
123+
uint32_t index;
124+
REQUIRE((values.IndexOf(true, index) && (index == 4)));
125+
126+
auto itr = values.First();
127+
REQUIRE(itr.HasCurrent());
128+
REQUIRE(!itr.Current());
129+
REQUIRE(itr.MoveNext());
130+
REQUIRE(itr.MoveNext());
131+
bool temp[5];
132+
REQUIRE(itr.GetMany(temp) == 3);
133+
REQUIRE((!temp[0] && !temp[1] && temp[2]));
134+
135+
values.RemoveAt(0);
136+
values.RemoveAtEnd();
137+
REQUIRE(values.Size() == 3);
138+
REQUIRE(values.GetMany(0, temp) == 3);
139+
REQUIRE((!temp[0] && !temp[1] && !temp[2]));
140+
values.Clear();
141+
REQUIRE(values.Size() == 0);
142+
}

0 commit comments

Comments
 (0)