File indexing completed on 2025-10-31 08:32:39
0001 
0002 
0003 
0004 
0005 #pragma once
0006 
0007 #include <cstdlib>
0008 #include <cxxabi.h>
0009 #include <fmt/format.h>
0010 #include <memory>
0011 #include <string>
0012 
0013 #include <algorithms/error.h>
0014 
0015 namespace algorithms::detail {
0016 
0017 template <class T> std::string demangledName() {
0018   const char* mangled = typeid(T).name();
0019   int status          = 1; 
0020                            
0021   std::unique_ptr<char, void (*)(void*)> res{abi::__cxa_demangle(mangled, NULL, NULL, &status),
0022                                              std::free};
0023   if (status != 0) {
0024     throw algorithms::Error(fmt::format("Failed to demangle type name: {}", mangled),
0025                             "algorithms::detail::demangledName()");
0026   }
0027 
0028   return res.get();
0029 }
0030 
0031 }