algorithms  2.2.0
Framework-independent algorithms for the EIC
Loading...
Searching...
No Matches
demangle.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (C) 2022 Wouter Deconinck, Sylvester Joosten
3//
4// Get a demangled type name string
5#pragma once
6
7#include <cstdlib>
8#include <cxxabi.h>
9#include <fmt/format.h>
10#include <memory>
11#include <string>
12
13#include <algorithms/error.h>
14
15namespace algorithms::detail {
16
17template <class T> std::string demangledName() {
18 const char* mangled = typeid(T).name();
19 int status = 1; // ABI spec sets status to 0 on success, so we need a different
20 // starting value
21 std::unique_ptr<char, void (*)(void*)> res{abi::__cxa_demangle(mangled, NULL, NULL, &status),
22 std::free};
23 if (status != 0) {
24 throw algorithms::Error(fmt::format("Failed to demangle type name: {}", mangled),
25 "algorithms::detail::demangledName()");
26 }
27
28 return res.get();
29}
30
31} // namespace algorithms::detail
std::string demangledName()
Definition demangle.h:17