Browse Source

* Fixed some small bugs

master
bergmann 4 years ago
parent
commit
c2244f6856
5 changed files with 23 additions and 5 deletions
  1. +2
    -2
      include/cppcore/conversion/enum.h
  2. +9
    -0
      include/cppcore/conversion/enum.inl
  3. +9
    -0
      include/cppcore/conversion/string.inl
  4. +1
    -1
      include/cppcore/misc/exception.h
  5. +2
    -2
      include/cppcore/misc/exception.inl

+ 2
- 2
include/cppcore/conversion/enum.h View File

@@ -12,7 +12,7 @@
namespace cppcore { \
namespace __impl { \
template<> \
struct enum_value_traits<enum> \
struct enum_value_traits<enum, void> \
{ \
using enum_type = enum; \
using enum_value_pair_type = std::pair<enum_type, std::string>; \
@@ -38,7 +38,7 @@ namespace cppcore
*
* @tparam T_enum Enum type.
*/
template<typename T_enum>
template<typename T_enum, typename = void>
struct enum_value_traits
{
using enum_type = T_enum;


+ 9
- 0
include/cppcore/conversion/enum.inl View File

@@ -8,6 +8,15 @@ namespace cppcore
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 */

template<typename T_enum, typename T_traits>


+ 9
- 0
include/cppcore/conversion/string.inl View File

@@ -159,6 +159,15 @@ namespace cppcore
{ 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>
struct op_to_string<T, decltype(std::declval<T>().to_string(std::declval<std::ostream&>()), void())>
{


+ 1
- 1
include/cppcore/misc/exception.h View File

@@ -91,7 +91,7 @@ namespace cppcore
/**
* @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.


+ 2
- 2
include/cppcore/misc/exception.inl View File

@@ -53,14 +53,14 @@ namespace cppcore
return os.str();
}

std::string exception::to_string() const
const std::string& exception::to_string() const
{
if (_msg_cache_empty)
{
_msg_cache = print();
_msg_cache_empty = false;
}
return _msg_cache.c_str();
return _msg_cache;
}

const char* exception::what() const throw()


Loading…
Cancel
Save