• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/core/debugging/include/hpx/debugging/demangle_helper.hpp
1
//  Copyright (c) 2017 John Biddiscombe
2
//  Copyright (c) 2007-2025 Hartmut Kaiser
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#pragma once
9

10
#include <hpx/config.hpp>
11

12
#include <string>
13
#include <typeinfo>
14

15
// --------------------------------------------------------------------
16
// Always present regardless of compiler : used by serialization code
17
// --------------------------------------------------------------------
18
namespace hpx::util::debug {
19

20
    HPX_CXX_EXPORT template <typename T>
21
    struct demangle_helper
22
    {
23
        [[nodiscard]] static char const* type_id() noexcept
24
        {
25
            return typeid(T).name();
26
        }
27
    };
28
}    // namespace hpx::util::debug
29

30
#if defined(__GNUG__)
31

32
#include <cstdlib>
33
#include <cxxabi.h>
34

35
#include <memory>
36

37
// --------------------------------------------------------------------
38
// if available : demangle an arbitrary c++ type using gnu utility
39
// --------------------------------------------------------------------
40
namespace hpx::util::debug {
41

42
    HPX_CXX_EXPORT template <typename T>
43
    class cxxabi_demangle_helper
44
    {
45
    public:
46
        cxxabi_demangle_helper()
47
          : demangled_{abi::__cxa_demangle(
48
                           typeid(T).name(), nullptr, nullptr, nullptr),
×
49
                std::free}
×
50
        {
51
        }
52

53
        [[nodiscard]] char const* type_id() const noexcept
×
54
        {
55
            return demangled_ ? demangled_.get() : typeid(T).name();
56
        }
57

×
58
    private:
59
        std::unique_ptr<char, void (*)(void*)> demangled_;
60
    };
61
}    // namespace hpx::util::debug
62

63
#else
64

65
namespace hpx::util::debug {
66

67
    HPX_CXX_EXPORT template <typename T>
68
    using cxxabi_demangle_helper = demangle_helper<T>;
69
}    // namespace hpx::util::debug
70

71
#endif
72

73
///////////////////////////////////////////////////////////////////////////////
74
namespace hpx::util::debug {
75

76
    HPX_CXX_EXPORT template <typename T>
77
    char const* type_id()
78
    {
79
        static cxxabi_demangle_helper<T> id = cxxabi_demangle_helper<T>();
80
        return id.type_id();
81
    }
82

83
    // --------------------------------------------------------------------
84
    // print type information
85
    // usage : std::cout << print_type<args...>("separator")
86
    // separator is appended if the number of types > 1
87
    // --------------------------------------------------------------------
88
    HPX_CXX_EXPORT template <typename T = void>
89
    std::string print_type(char const* = "")
90
    {
91
        return std::string(type_id<T>());
92
    }
93

94
    template <>
95
    inline std::string print_type<>(char const*)
96
    {
97
        return "void";
98
    }
99

100
    HPX_CXX_EXPORT template <typename T, typename... Args>
101
        requires(sizeof...(Args) != 0)
102
    std::string print_type(char const* delim = "")
103
    {
104
        std::string const temp = type_id<T>();
105
        return temp + delim + print_type<Args...>(delim);
106
    }
107
}    // namespace hpx::util::debug
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc