C++枚举类型转字符串
1. 参考
【鲜为人知的C++黑科技【PRETTY_FUNCTION】非侵入式的编译期反射-哔哩哔哩】
2. 源码
enum_enhanced.hpp
/**
* @file enum_enhanced.hpp
* @author chenpi001 (cp12138@duck.com)
* @brief convertion between enum and std::string, need c++11 or above
* @version 0.1
* @date 2022-08-03
*
* @copyright Copyright (c) 2022
*
*/
#pragma once
#include <string>
#include <type_traits>
namespace enum_enhanced
{
namespace enum_enhanced_impl
{
template <class T, T N>
char const *pretty_string()
{
#ifdef _MSC_VER
return __FUNCSIG__;
#else
return __PRETTY_FUNCTION__;
#endif
}
template <class T>
struct PrettyStringCaller