Quellcode durchsuchen

* Fixed memory leak in type_helper

master
bergmann vor 4 Jahren
Ursprung
Commit
68b49deed3
2 geänderte Dateien mit 26 neuen und 5 gelöschten Zeilen
  1. +1
    -1
      include/cppcore/misc/type_helper.h
  2. +25
    -4
      include/cppcore/misc/type_helper.inl

+ 1
- 1
include/cppcore/misc/type_helper.h Datei anzeigen

@@ -16,7 +16,7 @@ namespace cppcore
/** /**
* @brief Get the name of the type. * @brief Get the name of the type.
*/ */
static inline std::string name();
static inline const std::string& name();
}; };






+ 25
- 4
include/cppcore/misc/type_helper.inl Datei anzeigen

@@ -1,16 +1,37 @@
#pragma once #pragma once


#include <memory>

#include "type_helper.h" #include "type_helper.h"


namespace cppcore namespace cppcore
{ {


namespace __impl
{

template<typename T>
std::string get_type_name()
{
using ptr_u = std::unique_ptr<char, decltype(&free)>;

int status;
ptr_u name(
abi::__cxa_demangle(typeid(T).name(), 0, 0, &status),
&free);

return std::string(name
? name.get()
: typeid(T).name());
}

}

template<typename T> template<typename T>
std::string type_helper<T>::name()
const std::string& type_helper<T>::name()
{ {
int status;
auto name = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
return std::string(name ? name : typeid(T).name());
static auto value = __impl::get_type_name<T>();
return value;
} }


/** /**


Laden…
Abbrechen
Speichern