{"id":19536,"url":"https://patchwork.libcamera.org/api/1.1/patches/19536/?format=json","web_url":"https://patchwork.libcamera.org/patch/19536/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240225164348.10073-2-laurent.pinchart@ideasonboard.com>","date":"2024-02-25T16:43:46","name":"[1/2] libcamera: utils: Add to_underlying() helper function","commit_ref":"6a50c960be774b44a32f566f1f485cf800cc0527","pull_url":null,"state":"accepted","archived":false,"hash":"f7cfa32ea7aefa19126e829f0d0da1ceea59fc21","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19536/mbox/","series":[{"id":4179,"url":"https://patchwork.libcamera.org/api/1.1/series/4179/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4179","date":"2024-02-25T16:43:45","name":"libcamera: Add utils::to_underlying() helper","version":1,"mbox":"https://patchwork.libcamera.org/series/4179/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19536/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19536/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A7853BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 25 Feb 2024 16:43:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AE1D16286B;\n\tSun, 25 Feb 2024 17:43:48 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8730661CA1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 25 Feb 2024 17:43:46 +0100 (CET)","from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi\n\t[89.27.53.110])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AA8234E6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 25 Feb 2024 17:43:35 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Y/Uo833n\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1708879415;\n\tbh=d9h1gzUILf4BFiEHLiU/dEI9YPfQTYnYHJYYLNTcW8M=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Y/Uo833n9VTxiXOjhUUBzBq5bfqg5eKVd+06uLGzwPuCdzI0Os9oYpk3iQPks1XGz\n\tJ+g9Tt6NxlqVx6bBod6AnADkckETOGj9TfW+c/BDiqmeueaLS+jH5NkpAyRKE7nglQ\n\tKpUdWfcPmJB4PIHwQj1DgK6GVUlef7IH2sB+l890=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH 1/2] libcamera: utils: Add to_underlying() helper function","Date":"Sun, 25 Feb 2024 18:43:46 +0200","Message-ID":"<20240225164348.10073-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20240225164348.10073-1-laurent.pinchart@ideasonboard.com>","References":"<20240225164348.10073-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"C++23 has a std::to_underlying() helper function that converts an\nenumeration value to its underlying type. Add a compatible\nimplementation to the libcamera::utils namespace.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/base/utils.h |  6 ++++++\n src/libcamera/base/utils.cpp   | 10 ++++++++++\n 2 files changed, 16 insertions(+)","diff":"diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h\nindex 37d9af609ec7..922e4dfaf9fa 100644\n--- a/include/libcamera/base/utils.h\n+++ b/include/libcamera/base/utils.h\n@@ -369,6 +369,12 @@ decltype(auto) abs_diff(const T &a, const T &b)\n \n double strtod(const char *__restrict nptr, char **__restrict endptr);\n \n+template<class Enum>\n+constexpr std::underlying_type_t<Enum> to_underlying(Enum e) noexcept\n+{\n+\treturn static_cast<std::underlying_type_t<Enum>>(e);\n+}\n+\n } /* namespace utils */\n \n #ifndef __DOXYGEN__\ndiff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp\nindex 3b73b442260a..2f4c3177ac13 100644\n--- a/src/libcamera/base/utils.cpp\n+++ b/src/libcamera/base/utils.cpp\n@@ -521,6 +521,16 @@ double strtod(const char *__restrict nptr, char **__restrict endptr)\n #endif\n }\n \n+/**\n+ * \\fn to_underlying(Enum e)\n+ * \\brief Convert an enumeration to its underlygin type\n+ * \\param[in] e Enumeration value to convert\n+ *\n+ * This function is equivalent to the C++23 std::to_underlying().\n+ *\n+ * \\return The value of e converted to its underlying type\n+ */\n+\n } /* namespace utils */\n \n #ifndef __DOXYGEN__\n","prefixes":["1/2"]}