24.02.1
Utils.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2021,2023 Arm Limited.
3
*
4
* SPDX-License-Identifier: MIT
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to
8
* deal in the Software without restriction, including without limitation the
9
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
* sell copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in all
14
* copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* SOFTWARE.
23
*/
24
#ifndef SRC_COMMON_UTILS_H
25
#define SRC_COMMON_UTILS_H
26
27
#include <algorithm>
28
#include <initializer_list>
29
#include <type_traits>
30
31
namespace
arm_compute
32
{
33
namespace
utils
34
{
35
/** Convert a strongly typed enum to an old plain c enum
36
*
37
* @tparam E Plain old C enum
38
* @tparam SE Strongly typed resulting enum
39
*
40
* @param[in] v Value to convert
41
*
42
* @return A corresponding plain old C enumeration
43
*/
44
template
<
typename
E,
typename
SE>
45
constexpr E
as_cenum
(
const
SE v) noexcept
46
{
47
return
static_cast<
E
>
(
static_cast<
std::underlying_type_t<SE>
>
(v));
48
}
49
50
/** Convert plain old enumeration to a strongly typed enum
51
*
52
* @tparam SE Strongly typed resulting enum
53
* @tparam E Plain old C enum
54
*
55
* @param[in] val Value to convert
56
*
57
* @return A corresponding strongly typed enumeration
58
*/
59
template
<
typename
SE,
typename
E>
60
constexpr SE
as_enum
(
const
E val) noexcept
61
{
62
return
static_cast<
SE
>
(val);
63
}
64
65
/** Check if the given value is in the given enum value list
66
*
67
* @tparam E The type of the enum
68
*
69
* @param[in] check Value to check
70
* @param[in] list List of enum values to check against
71
*
72
* @return True if the given value is found in the list
73
*/
74
template
<
typename
E>
75
bool
is_in
(E check, std::initializer_list<E> list)
76
{
77
return
std::any_of(list.begin(), list.end(), [&check](E e) { return check == e; });
78
}
79
}
// namespace utils
80
}
// namespace arm_compute
81
82
#endif
/* SRC_COMMON_UTILS_H */
arm_compute::utils::as_enum
constexpr SE as_enum(const E val) noexcept
Convert plain old enumeration to a strongly typed enum.
Definition:
Utils.h:60
arm_compute::utils::is_in
bool is_in(E check, std::initializer_list< E > list)
Check if the given value is in the given enum value list.
Definition:
Utils.h:75
arm_compute
Copyright (c) 2017-2024 Arm Limited.
Definition:
introduction.dox:24
arm_compute::utils::as_cenum
constexpr E as_cenum(const SE v) noexcept
Convert a strongly typed enum to an old plain c enum.
Definition:
Utils.h:45
src
common
utils
Utils.h
Generated on Mon Mar 18 2024 11:31:55 for Compute Library by
1.8.17