diff options
Diffstat (limited to 'src/common/utils/Utils.h')
-rw-r--r-- | src/common/utils/Utils.h | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/common/utils/Utils.h b/src/common/utils/Utils.h index 9602c32f62..33fe6c0e81 100644 --- a/src/common/utils/Utils.h +++ b/src/common/utils/Utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited. + * Copyright (c) 2021,2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,8 @@ #ifndef SRC_COMMON_UTILS_H #define SRC_COMMON_UTILS_H +#include <algorithm> +#include <initializer_list> #include <type_traits> namespace arm_compute @@ -40,10 +42,26 @@ namespace utils * @return A corresponding plain old C enumeration */ template <typename E, typename SE> -constexpr E as_cenum(SE v) noexcept +constexpr E as_cenum(const SE v) noexcept { return static_cast<E>(static_cast<std::underlying_type_t<SE>>(v)); } + +/** Convert plain old enumeration to a strongly typed enum + * + * @tparam SE Strongly typed resulting enum + * @tparam E Plain old C enum + * + * @param[in] val Value to convert + * + * @return A corresponding strongly typed enumeration + */ +template <typename SE, typename E> +constexpr SE as_enum(const E val) noexcept +{ + return static_cast<SE>(val); +} + /** Check if the given value is in the given enum value list * * @tparam E The type of the enum @@ -56,10 +74,7 @@ constexpr E as_cenum(SE v) noexcept template <typename E> bool is_in(E check, std::initializer_list<E> list) { - return std::any_of(std::cbegin(list), std::cend(list), [&check](E e) - { - return check == e; - }); + return std::any_of(list.begin(), list.end(), [&check](E e) { return check == e; }); } } // namespace utils } // namespace arm_compute |