AK: Fix the JsonArray constructor for accepting an iterable type

There were a couple of issues here. First, the IterableContainerOf
concept was testing if dereferencing an iterator of ContainerType<T>
returns a value of type T. However, it should return a T&.

Second, the constructor was trying to move values out of a constant
reference to the container. We now accept both lvalue and rvalue
containers.
This commit is contained in:
Timothy Flynn 2025-03-03 17:08:49 -05:00 committed by Tim Flynn
parent 38197916c3
commit 1adcaf7181
Notes: github-actions[bot] 2025-03-04 20:35:11 +00:00
2 changed files with 9 additions and 2 deletions

View file

@ -126,7 +126,7 @@ template<typename T, typename ValueT>
concept IterableContainerOf = IterableContainer<T> && requires {
{
*declval<T>().begin()
} -> SameAs<ValueT>;
} -> SameAs<ValueT&>;
};
template<typename Func, typename... Args>

View file

@ -38,12 +38,19 @@ public:
}
template<IterableContainerOf<JsonValue> ContainerT>
JsonArray(ContainerT const& source)
JsonArray(ContainerT&& source)
{
for (auto& value : source)
m_values.append(move(value));
}
template<IterableContainerOf<JsonValue> ContainerT>
JsonArray(ContainerT const& source)
{
for (auto const& value : source)
m_values.append(value);
}
JsonArray& operator=(JsonArray const& other)
{
if (this != &other)