Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:32:41

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Wouter Deconinck, Sylvester Joosten
0003 //
0004 // Get a demangled type name string
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; // ABI spec sets status to 0 on success, so we need a different
0020                            // starting value
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 } // namespace algorithms::detail