Debian Codegraph @

common/include/d_underlying_value.h

raw
1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7 #pragma once
8
9 #include <type_traits>
10
11 /* Convenience function to use std::underlying_type<T> on a given value,
12 * and always pick the right T for the enum being converted.
13 */
14 template <typename T, typename R = typename std::enable_if<std::is_enum<T>::value, typename std::underlying_type<T>::type>::type>
15 static constexpr R underlying_value(const T e)
16 {
17 return static_cast<R>(e);
18 }
19
20 template <typename T>
21 typename std::enable_if<!std::is_enum<T>::value, T>::type underlying_value(T) = delete;