diff --git a/simgear/sg_inlines.h b/simgear/sg_inlines.h index b21304d8..4c4b4ad5 100644 --- a/simgear/sg_inlines.h +++ b/simgear/sg_inlines.h @@ -23,6 +23,7 @@ // // $Id$ +#include #include #ifndef _SG_INLINES_H @@ -123,6 +124,17 @@ void noexceptSwap(T& a, T& b) noexcept swap(a, b); } +// Cast an enum value to its underlying type (useful with scoped enumerations). +// +// Example: enum class MyEnum { first = 1, second }; +// auto e = MyEnum::second; +// std::string msg = "MyEnum::second is " + +// std::to_string(simgear::enumValue(e)); +template +constexpr typename std::underlying_type::type enumValue(T e) { + return static_cast::type>(e); +} + } // of namespace simgear #endif // _SG_INLINES_H