From 6a50c960be774b44a32f566f1f485cf800cc0527 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 23 Feb 2024 16:55:15 +0200 Subject: libcamera: utils: Add to_underlying() helper function 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 Reviewed-by: Jacopo Mondi Reviewed-by: Naushir Patuck --- include/libcamera/base/utils.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h index 37d9af60..922e4dfa 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__ -- cgit v1.2.1