From patchwork Sun Feb 25 16:43:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 19536 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 A7853BD160 for ; Sun, 25 Feb 2024 16:43:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE1D16286B; Sun, 25 Feb 2024 17:43:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Y/Uo833n"; 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 8730661CA1 for ; Sun, 25 Feb 2024 17:43:46 +0100 (CET) Received: from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AA8234E6 for ; Sun, 25 Feb 2024 17:43:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708879415; bh=d9h1gzUILf4BFiEHLiU/dEI9YPfQTYnYHJYYLNTcW8M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Y/Uo833n9VTxiXOjhUUBzBq5bfqg5eKVd+06uLGzwPuCdzI0Os9oYpk3iQPks1XGz J+g9Tt6NxlqVx6bBod6AnADkckETOGj9TfW+c/BDiqmeueaLS+jH5NkpAyRKE7nglQ KpUdWfcPmJB4PIHwQj1DgK6GVUlef7IH2sB+l890= From: Laurent Pinchart 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 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" C++23 has a std::to_underlying() helper function that converts an enumeration value to its underlying type. Add a compatible implementation to the libcamera::utils namespace. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/base/utils.h | 6 ++++++ src/libcamera/base/utils.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 37d9af609ec7..922e4dfaf9fa 100644 --- a/include/libcamera/base/utils.h +++ b/include/libcamera/base/utils.h @@ -369,6 +369,12 @@ decltype(auto) abs_diff(const T &a, const T &b) double strtod(const char *__restrict nptr, char **__restrict endptr); +template +constexpr std::underlying_type_t to_underlying(Enum e) noexcept +{ + return static_cast>(e); +} + } /* namespace utils */ #ifndef __DOXYGEN__ diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp index 3b73b442260a..2f4c3177ac13 100644 --- a/src/libcamera/base/utils.cpp +++ b/src/libcamera/base/utils.cpp @@ -521,6 +521,16 @@ double strtod(const char *__restrict nptr, char **__restrict endptr) #endif } +/** + * \fn to_underlying(Enum e) + * \brief Convert an enumeration to its underlygin type + * \param[in] e Enumeration value to convert + * + * This function is equivalent to the C++23 std::to_underlying(). + * + * \return The value of e converted to its underlying type + */ + } /* namespace utils */ #ifndef __DOXYGEN__