Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions strings/base_collections_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ namespace winrt::impl
struct removed_value
{
// Trivially destructible; okay to run destructor under lock
void assign(T&) {}
template <typename U>
void assign(U&&) {}
};

template <typename T>
struct removed_value<T, std::enable_if_t<std::is_move_constructible_v<T> && !std::is_trivially_destructible_v<T>>>
{
std::optional<T> m_value;

void assign(T& value)
template <typename U>
void assign(U&& value)
{
m_value.emplace(std::move(value));
}
Expand Down Expand Up @@ -313,7 +315,7 @@ WINRT_EXPORT namespace winrt
}

this->increment_version();
auto& pos = static_cast<D&>(*this).get_container()[index];
auto&& pos = static_cast<D&>(*this).get_container()[index];
oldValue.assign(pos);
pos = static_cast<D const&>(*this).wrap_value(value);
}
Expand Down
30 changes: 30 additions & 0 deletions test/old_tests/UnitTests/single_threaded_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,33 @@ TEST_CASE("test_single_threaded_vector")
test_vector(single_threaded_vector<int>());
test_vector(single_threaded_observable_vector<int>());
}

TEST_CASE("single_threaded_vector of bool")
{
auto values = single_threaded_vector<bool>();
values.Append(true);
values.ReplaceAll({ false, true, false, true });
values.InsertAt(1, false);
values.SetAt(2, false);
REQUIRE(values.Size() == 5);
REQUIRE(!values.GetAt(0));
uint32_t index;
REQUIRE((values.IndexOf(true, index) && (index == 4)));

auto itr = values.First();
REQUIRE(itr.HasCurrent());
REQUIRE(!itr.Current());
REQUIRE(itr.MoveNext());
REQUIRE(itr.MoveNext());
bool temp[5];
REQUIRE(itr.GetMany(temp) == 3);
REQUIRE((!temp[0] && !temp[1] && temp[2]));

values.RemoveAt(0);
values.RemoveAtEnd();
REQUIRE(values.Size() == 3);
REQUIRE(values.GetMany(0, temp) == 3);
REQUIRE((!temp[0] && !temp[1] && !temp[2]));
values.Clear();
REQUIRE(values.Size() == 0);
}