From patchwork Thu Apr 3 15:49:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23120 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1FCCFC327D for ; Thu, 3 Apr 2025 15:49:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D1299689B0; Thu, 3 Apr 2025 17:49:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OGQD3KOF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EFD4689AB for ; Thu, 3 Apr 2025 17:49:47 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:6d9d:9854:3fc1:4bb2]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8614D11E9; Thu, 3 Apr 2025 17:47:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743695273; bh=fS1S7ccPPk7/gi+Who3oQC3Xq9n+HV5xUYPEfyPmlJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OGQD3KOFsKFE339b8vAPsN1RJwLOVFSAopNBrYAYKXdEka0LZZ86TJux/E6scXccG qFAJvXEgfw+vOmEhFm57vuBHdeq1cfXQosawcWL79bRu4o4nwg3vD2Tg4lTLYCv2xY dzROQkZKG/tWFCK4YPiLsQXNoAziN52LxxzSruP8= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Laurent Pinchart Subject: [PATCH v3 04/16] libcamera: vector: Add a Span based constructor Date: Thu, 3 Apr 2025 17:49:09 +0200 Message-ID: <20250403154925.382973-5-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250403154925.382973-1-stefan.klug@ideasonboard.com> References: <20250403154925.382973-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When one wants to create a Vector from existing data, currently the only way is via std::array. Add a Span based constructor to allow creation from std::vectors and alike. While at it, replace the manual loop with std::copy. Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart --- Changes in v2: - Added this patch Changes in v3: - Improved commit message - Added constexpr to the contructor - Pass Span by value - Removed initializer of data_ member which was only needed for the default constructor to be actually constexpr. But Vector is not used as constexpr anywhere, so we can leave that as is (This will fix itself with C++20). --- include/libcamera/internal/vector.h | 8 ++++++-- src/libcamera/vector.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index a67a09474204..4e9ef1ee6853 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -42,8 +42,12 @@ public: constexpr Vector(const std::array &data) { - for (unsigned int i = 0; i < Rows; i++) - data_[i] = data[i]; + std::copy(data.begin(), data.end(), data_.begin()); + } + + constexpr Vector(const Span data) + { + std::copy(data.begin(), data.end(), data_.begin()); } const T &operator[](size_t i) const diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp index 85ca2208245a..5567d5b8defb 100644 --- a/src/libcamera/vector.cpp +++ b/src/libcamera/vector.cpp @@ -44,6 +44,14 @@ LOG_DEFINE_CATEGORY(Vector) * The size of \a data must be equal to the dimension size Rows of the vector. */ +/** + * \fn Vector::Vector(const Span data) + * \brief Construct vector from supplied data + * \param data Data from which to construct a vector + * + * The size of \a data must be equal to the dimension size Rows of the vector. + */ + /** * \fn T Vector::operator[](size_t i) const * \brief Index to an element in the vector