Skip to content

Commit

Permalink
Implement type_name on GCC and fix on older Clangs
Browse files Browse the repository at this point in the history
  • Loading branch information
ldionne committed Nov 13, 2023
1 parent 4cff7d3 commit af2603d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions include/boost/hana/experimental/type_name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ namespace boost { namespace hana { namespace experimental {

// Note: We substract the null terminator from the string sizes below.
template <typename T>
constexpr cstring type_name_impl2() {

#if defined(__clang__)
constexpr auto type_name_impl2() {
#if defined(BOOST_HANA_CONFIG_CLANG)
constexpr char const* pretty_function = __PRETTY_FUNCTION__;
constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
constexpr std::size_t prefix_size = sizeof("auto boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
constexpr std::size_t suffix_size = sizeof("]") - 1;
#elif defined(BOOST_HANA_CONFIG_GCC)
constexpr char const* pretty_function = __PRETTY_FUNCTION__;
constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
constexpr std::size_t prefix_size = sizeof("cstring boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
constexpr std::size_t prefix_size = sizeof("constexpr auto boost::hana::experimental::detail::type_name_impl2() [with T = ") - 1;
constexpr std::size_t suffix_size = sizeof("]") - 1;
#else
#error "No support for this compiler."
#endif

return {pretty_function + prefix_size, total_size - prefix_size - suffix_size};
cstring s{pretty_function + prefix_size, total_size - prefix_size - suffix_size};
return s;
}

template <typename T, std::size_t ...i>
Expand Down

0 comments on commit af2603d

Please sign in to comment.