JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
type_name.h File Reference

Compile-time type name extraction using compiler-specific macros. More...

#include <string_view>
#include "jh/macros/platform.h"

Go to the source code of this file.

Namespaces

namespace  jh::macro
 Internal macro-based utilities.

Functions

template<typename T>
constexpr std::string_view jh::macro::type_name ()
 Extract the human-readable type name of T at compile time.

Detailed Description

Compile-time type name extraction using compiler-specific macros.

Author
JeongHan-Bae <mastropseudo@gmail.com>

This header provides jh::macro::type_name<T>(), which extracts the unmangled type name of T from PRETTY_FUNCTION (Clang/GCC) without requiring RTTI.

Design Notes:

  • Implemented with compiler-dependent "macro magic".
  • No ABI or RTTI dependency — works even with -fno-rtti.
  • Only intended for debugging, logging, and diagnostics.
  • Do not rely on this in production logic:
    • Output is compiler- and version-specific.
    • Format may change between toolchains.
    • No guarantees of stability across builds.

Usage Example:

std::cout << jh::macro::type_name<int>(); // "int"
std::cout << jh::macro::type_name<array<int, 4>>(); // "jh::pod::array<int, 4>"
Note
Falls back to "unknown" if compiler is unsupported.
Not suitable for serialization or program logic.
Version
1.3.x
Date
2025