@@ -12,7 +12,7 @@ | |||||
namespace cppcore { \ | namespace cppcore { \ | ||||
namespace __impl { \ | namespace __impl { \ | ||||
template<> \ | template<> \ | ||||
struct enum_value_traits<enum> \ | |||||
struct enum_value_traits<enum, void> \ | |||||
{ \ | { \ | ||||
using enum_type = enum; \ | using enum_type = enum; \ | ||||
using enum_value_pair_type = std::pair<enum_type, std::string>; \ | using enum_value_pair_type = std::pair<enum_type, std::string>; \ | ||||
@@ -38,7 +38,7 @@ namespace cppcore | |||||
* | * | ||||
* @tparam T_enum Enum type. | * @tparam T_enum Enum type. | ||||
*/ | */ | ||||
template<typename T_enum> | |||||
template<typename T_enum, typename = void> | |||||
struct enum_value_traits | struct enum_value_traits | ||||
{ | { | ||||
using enum_type = T_enum; | using enum_type = T_enum; | ||||
@@ -8,6 +8,15 @@ namespace cppcore | |||||
namespace __impl | namespace __impl | ||||
{ | { | ||||
/* enum_value_traits */ | |||||
template<typename T_enum, typename T_enable> | |||||
decltype(auto) enum_value_traits<T_enum, T_enable>::get_enum_values() | |||||
{ | |||||
static const auto value = enum_value_vector_type(); | |||||
return value; | |||||
} | |||||
/* enum_conversion_traits */ | /* enum_conversion_traits */ | ||||
template<typename T_enum, typename T_traits> | template<typename T_enum, typename T_traits> | ||||
@@ -159,6 +159,15 @@ namespace cppcore | |||||
{ return std::string(v, N-1); } | { return std::string(v, N-1); } | ||||
}; | }; | ||||
template<typename T> | |||||
struct op_to_string<T*, std::enable_if_t<std::is_same_v<std::decay_t<T>, char>>> | |||||
{ | |||||
using value_type = T*; | |||||
inline std::string operator()(const value_type& v) const | |||||
{ return std::string(v); } | |||||
}; | |||||
template<typename T> | template<typename T> | ||||
struct op_to_string<T, decltype(std::declval<T>().to_string(std::declval<std::ostream&>()), void())> | struct op_to_string<T, decltype(std::declval<T>().to_string(std::declval<std::ostream&>()), void())> | ||||
{ | { | ||||
@@ -91,7 +91,7 @@ namespace cppcore | |||||
/** | /** | ||||
* @brief Convert the exception to a string. | * @brief Convert the exception to a string. | ||||
*/ | */ | ||||
inline std::string to_string() const; | |||||
inline const std::string& to_string() const; | |||||
/** | /** | ||||
* @brief Get the message of the exception as c-string. | * @brief Get the message of the exception as c-string. | ||||
@@ -53,14 +53,14 @@ namespace cppcore | |||||
return os.str(); | return os.str(); | ||||
} | } | ||||
std::string exception::to_string() const | |||||
const std::string& exception::to_string() const | |||||
{ | { | ||||
if (_msg_cache_empty) | if (_msg_cache_empty) | ||||
{ | { | ||||
_msg_cache = print(); | _msg_cache = print(); | ||||
_msg_cache_empty = false; | _msg_cache_empty = false; | ||||
} | } | ||||
return _msg_cache.c_str(); | |||||
return _msg_cache; | |||||
} | } | ||||
const char* exception::what() const throw() | const char* exception::what() const throw() | ||||