How can I output the value of an enum class in C++11

前端 未结 7 2258
面向向阳花
面向向阳花 2020-11-30 19:00

How can I output the value of an enum class in C++11? In C++03 it\'s like this:

#include 

using namespace std;

enum A {
  a =          


        
7条回答
  •  [愿得一人]
    2020-11-30 20:00

    Following worked for me in C++11:

    template 
    constexpr typename std::enable_if::value,
                                      typename std::underlying_type::type>::type
    to_integral(Enum const& value) {
        return static_cast::type>(value);
    }
    

提交回复
热议问题