From patchwork Mon Sep 6 22:56:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13667 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 A6D6FBE175 for ; Mon, 6 Sep 2021 22:57:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BFD5C69170; Tue, 7 Sep 2021 00:57:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jCqBJnO/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 458BE60253 for ; Tue, 7 Sep 2021 00:56:59 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C362891; Tue, 7 Sep 2021 00:56:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630969018; bh=pC+gqSk8VFETXj3WCksnBoLMDUBsNbccZli0wVQuRv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jCqBJnO/doWDS4RClt5VKuRwRG753xZGre5IXLxSFWJxOs2npBIxwtj88sAlxNAKb KfpO1X56f7mFVf+/iL/tmGTMHfPfBkP4xr7Gel2hE5IxmC9uiM2gKck+MYwo6uv1/f xmqdfud/+VGJlsZvyppfTOwhlQIO2p04T7zl2pSM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Sep 2021 01:56:07 +0300 Message-Id: <20210906225636.14683-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> References: <20210906225420.13275-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 01/30] libcamera: base: utils: Use size_t for index in utils::enumerate() 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" The index generated by utils::enumerate() is an iteration counter, which should thus be positive. Use std::size_t instead of the difference_type of the container. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jean-Michel Hautbois Reviewed-by: Paul Elder Reviewed-by: Hirokazu Honda --- include/libcamera/base/utils.h | 4 ++-- test/utils.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 52301254c2eb..2b761436a99f 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -246,7 +246,7 @@ private: public: using difference_type = typename std::iterator_traits::difference_type; - using value_type = std::pair; + using value_type = std::pair; using pointer = value_type *; using reference = value_type &; using iterator_category = std::input_iterator_tag; @@ -275,7 +275,7 @@ public: private: Base current_; - difference_type pos_; + std::size_t pos_; }; template diff --git a/test/utils.cpp b/test/utils.cpp index d7f810e95e7a..d65467b5102c 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -77,8 +77,8 @@ protected: int testEnumerate() { - std::vector integers{ 1, 2, 3, 4, 5 }; - int i = 0; + std::vector integers{ 1, 2, 3, 4, 5 }; + unsigned int i = 0; for (auto [index, value] : utils::enumerate(integers)) { if (index != i || value != i + 1) { @@ -93,12 +93,12 @@ protected: ++i; } - if (integers != std::vector{ 0, 1, 2, 3, 4 }) { + if (integers != std::vector{ 0, 1, 2, 3, 4 }) { cerr << "Failed to modify container in enumerated range loop" << endl; return TestFail; } - Span span{ integers }; + Span span{ integers }; i = 0; for (auto [index, value] : utils::enumerate(span)) { @@ -112,7 +112,7 @@ protected: ++i; } - const int array[] = { 0, 2, 4, 6, 8 }; + const unsigned int array[] = { 0, 2, 4, 6, 8 }; i = 0; for (auto [index, value] : utils::enumerate(array)) {