1 // Copyright 2019 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_TORQUE_RUNTIME_SUPPORT_H_ 6 #define V8_TORQUE_RUNTIME_SUPPORT_H_ 7 8 #include <type_traits> 9 10 template <class T> 11 struct Identity { 12 using type = T; 13 }; 14 15 template <class T> 16 struct UnderlyingTypeHelper : Identity<typename std::underlying_type<T>::type> { 17 }; 18 19 template <class T> 20 using UnderlyingTypeIfEnum = 21 typename std::conditional_t<std::is_enum<T>::value, UnderlyingTypeHelper<T>, 22 Identity<T>>::type; 23 24 // Utility for extracting the underlying type of an enum, returns the type 25 // itself if not an enum. 26 template <class T> CastToUnderlyingTypeIfEnum(T x)27UnderlyingTypeIfEnum<T> CastToUnderlyingTypeIfEnum(T x) { 28 return static_cast<UnderlyingTypeIfEnum<T>>(x); 29 } 30 31 #endif // V8_TORQUE_RUNTIME_SUPPORT_H_ 32