2021-09-04 12:17:14 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
/* Convenience function to use std::underlying_type<T> on a given value,
|
|
|
|
* and always pick the right T for the enum being converted.
|
|
|
|
*/
|
2022-06-11 15:00:02 +00:00
|
|
|
template <typename T, typename R = typename std::enable_if<std::is_enum<T>::value, typename std::underlying_type<T>::type>::type>
|
|
|
|
static constexpr R underlying_value(const T e)
|
2021-09-04 12:17:14 +00:00
|
|
|
{
|
2022-06-11 15:00:02 +00:00
|
|
|
return static_cast<R>(e);
|
2021-09-04 12:17:14 +00:00
|
|
|
}
|
2022-06-11 15:00:02 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
typename std::enable_if<!std::is_enum<T>::value, T>::type underlying_value(T) = delete;
|