forked from KhronosGroup/SYCL-CTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion.h
31 lines (25 loc) · 841 Bytes
/
conversion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*******************************************************************************
//
// SYCL 2020 Conformance Test Suite
//
*******************************************************************************/
#ifndef __SYCLCTS_UTIL_CONVERSION_H
#define __SYCLCTS_UTIL_CONVERSION_H
#include <type_traits>
namespace {
/**
* @brief Static cast scoped enum value to the underlying type
*/
template <typename enumT>
constexpr auto to_integral(enumT const& value) {
if constexpr (std::is_enum_v<enumT>) {
return static_cast<typename std::underlying_type<enumT>::type>(value);
} else if constexpr (std::is_integral_v<enumT>) {
return value;
} else {
constexpr bool always_false = !std::is_same_v<enumT, enumT>;
static_assert(always_false, "Unsupported type");
}
}
} // namespace
#endif // __SYCLCTS_UTIL_CONVERSION_H