{"id":13730501,"url":"https://github.com/willwray/type_name","last_synced_at":"2025-05-08T03:30:46.003Z","repository":{"id":170414183,"uuid":"57679701","full_name":"willwray/type_name","owner":"willwray","description":"C++ type_name template utilities for pretty-printing type names","archived":false,"fork":false,"pushed_at":"2019-02-01T21:06:29.000Z","size":41,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-14T21:38:05.340Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willwray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-01T17:12:15.000Z","updated_at":"2024-09-03T16:21:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"858a3342-d7b1-4d83-9033-fbddb5013fea","html_url":"https://github.com/willwray/type_name","commit_stats":null,"previous_names":["willwray/type_name"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Ftype_name","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Ftype_name/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Ftype_name/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Ftype_name/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willwray","download_url":"https://codeload.github.com/willwray/type_name/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252992851,"owners_count":21837181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:15.750Z","updated_at":"2025-05-08T03:30:45.996Z","avatar_url":"https://github.com/willwray.png","language":"C++","readme":"# type_name\n\n## C++ `type_name` utilities for pretty-printing  type names.\n\nOriginally inspired by [Howard Hinnant's type_name code](#HH), posted in reponse to:   \n\u003e\"[How can I see the type deduced for a template type parameter?](http://stackoverflow.com/a/18369732)\"  \nStackOverflow, August 2013.  \n\nThe implementation is based on C++ typeinfo (RTTI, to become constexpr in C++20).  \n\n```c++\n  typeid(T).name()\n```\n\nOn GCC, Clang and compilers using the [Itanium ABI](http://mentorembedded.github.io/cxx-abi/) the result is a mangled name.  \nOn these platforms the name is demangled using the `abi::__cxa_demangle()` function.\n\n## C++17 `\u003ctype_name_rt\u003e`\n\n1. `type_name_str\u003cT\u003e()`  \n Returns a `std::string` copy of the demangled `typeid` name.  \n On each call it does all the work, and cleans it all up  \n (i.e. it frees any demangle allocation once copied from).\n\n2. `type_name_rt\u003cT\u003e`  \nA `std::string_view` global constant (a view into the  \ndemangle buffer, on CXXABI, which is not ever free'd).  \nAll work is done in static initialization, before main()\n\n* Failure is signaled by an empty return value; `\"\"`  \n(indicates a demangle failure as typeid is assumed failsafe).  \n\n### Requirements\n\nC++17 for `string_view`, constexpr-if and `__has_include`  \nRTTI, the compiler's runtime type information, must be enabled.\n\n### Dependencies\n\nFrom `std`:\n\u003e`\u003ccstring\u003e` for `std::strlen`  \n`\u003cstring\u003e`,`\u003cstring_view\u003e` as the return values.  \n`\u003ctype_traits\u003e` for `std::conditional`.  \n`\u003ctypeinfo\u003e` (RTTI) for typeid(T).name(), an implementation-defined name.  \n`\u003ccstdlib\u003e` for `std::free`.  \n`\u003cmemory\u003e` for `std::unique_ptr`\n\nPlatform dependency:\n\u003e`\u003ccxxabi.h\u003e` for demangling (on CXXABI platforms only - GCC, Clang, etc.)  \n\n### Usage example\n\nBecause the type is supplied as a template parameter, `decltype(expr)` is required  \nto query the type of an expression:\n\n```C++\n    const volatile char abc[1][2][3]{};\n    std::cout \u003c\u003c type_name_rt\u003cdecltype(abc)\u003e();\n```\n\n...produces output (different format is possible on different platforms):\n\n```\n  char const volatile [1][2][3]\n```\n\n## Design notes\nFirstly, note that the type argument has to be provided as a template parameter; type deduction from a regular function argument is not sufficient because deduction cannot distinguish all possible passed types. In other words, it is not possible to wrap `decltype()` or implement it otherwise.\n\nIn principal, with the type known at compile time, a fully constexpr implementation of  `type_name\u003cT\u003e` should be possible, for example as a constexpr variable template whose value is some compile-time string type containing the human-readable type name.\n\nIn practice, when based on the C++ `typeid()` operator, a fully constexpr implementation is not generally possible.\n\n\n\u003ch3 id=\"HH\"\u003eHoward Hinnant's C++11 type_name code\u003c/h3\u003e\n\n```C++\ntemplate \u003ctypename T\u003e\nstd::string\ntype_name()\n{\n    using TR = typename std::remove_reference\u003cT\u003e::type;\n    std::unique_ptr\u003cchar, void(*)(void*)\u003e own (\n    #ifndef _MSC_VER\n        abi::__cxa_demangle (typeid(TR).name(), nullptr,\n            nullptr, nullptr),\n    #else\n            nullptr,\n    #endif\n            std::free\n    );\n    std::string r = own != nullptr ? own.get() : typeid(TR).name();\n    if (std::is_const\u003cTR\u003e::value)\n        r += \" const\";\n    if (std::is_volatile\u003cTR\u003e::value)\n        r += \" volatile\";\n    if (std::is_lvalue_reference\u003cT\u003e::value)\n        r += \"\u0026\";\n    else if (std::is_rvalue_reference\u003cT\u003e::value)\n        r += \"\u0026\u0026\";\n    return r;\n}\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillwray%2Ftype_name","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillwray%2Ftype_name","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillwray%2Ftype_name/lists"}