Skip to content

Commit e820551

Browse files
committed
Implement type_name on GCC and fix on older Clangs
1 parent f649baa commit e820551

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

include/boost/hana/experimental/type_name.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,23 @@ namespace boost { namespace hana { namespace experimental {
2626

2727
// Note: We substract the null terminator from the string sizes below.
2828
template <typename T>
29-
constexpr cstring type_name_impl2() {
30-
31-
#if defined(__clang__)
29+
constexpr auto type_name_impl2() {
30+
#if defined(BOOST_HANA_CONFIG_CLANG)
31+
constexpr char const* pretty_function = __PRETTY_FUNCTION__;
32+
constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
33+
constexpr std::size_t prefix_size = sizeof("auto boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
34+
constexpr std::size_t suffix_size = sizeof("]") - 1;
35+
#elif defined(BOOST_HANA_CONFIG_GCC)
3236
constexpr char const* pretty_function = __PRETTY_FUNCTION__;
3337
constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
34-
constexpr std::size_t prefix_size = sizeof("cstring boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
38+
constexpr std::size_t prefix_size = sizeof("constexpr auto boost::hana::experimental::detail::type_name_impl2() [with T = ") - 1;
3539
constexpr std::size_t suffix_size = sizeof("]") - 1;
3640
#else
3741
#error "No support for this compiler."
3842
#endif
3943

40-
return {pretty_function + prefix_size, total_size - prefix_size - suffix_size};
44+
cstring s{pretty_function + prefix_size, total_size - prefix_size - suffix_size};
45+
return s;
4146
}
4247

4348
template <typename T, std::size_t ...i>

0 commit comments

Comments
 (0)