From 1adcaf718150859749ca7b1f933d5659322108fc Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 3 Mar 2025 17:08:49 -0500 Subject: [PATCH] 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 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. --- AK/Concepts.h | 2 +- AK/JsonArray.h | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AK/Concepts.h b/AK/Concepts.h index e6a7be77c44..3dda34c887f 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -126,7 +126,7 @@ template concept IterableContainerOf = IterableContainer && requires { { *declval().begin() - } -> SameAs; + } -> SameAs; }; template diff --git a/AK/JsonArray.h b/AK/JsonArray.h index bd0106d1b31..58a524b3f44 100644 --- a/AK/JsonArray.h +++ b/AK/JsonArray.h @@ -38,12 +38,19 @@ public: } template ContainerT> - JsonArray(ContainerT const& source) + JsonArray(ContainerT&& source) { for (auto& value : source) m_values.append(move(value)); } + template ContainerT> + JsonArray(ContainerT const& source) + { + for (auto const& value : source) + m_values.append(value); + } + JsonArray& operator=(JsonArray const& other) { if (this != &other)