Skip to content

Commit

Permalink
Enable constexpr __PRETTY_FUNCTION__ only for gcc >= 9.1.0.
Browse files Browse the repository at this point in the history
See also: Manu343726/ctti#35

Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow committed Sep 7, 2021
1 parent 5218f24 commit aefdac4
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/common/util/typename.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ inline const std::string typename_unpack_args() {
return type_name<T>() + "," + typename_unpack_args<U, Args...>();
}

#if defined(__VINEYARD_GCC_VERSION) && \
(__VINEYARD_GCC_VERSION <= 50100 || __VINEYARD_GCC_VERSION >= 70200)
#if defined(__VINEYARD_GCC_VERSION) && __VINEYARD_GCC_VERSION <= 90100

#if defined(__clang__)
#define __TYPENAME_FROM_FUNCTION_PREFIX \
Expand Down Expand Up @@ -80,18 +79,24 @@ inline const std::string __typename_from_function() {

template <typename T>
inline const std::string typename_impl(T const&) {
#if defined(__VINEYARD_GCC_VERSION) && \
(__VINEYARD_GCC_VERSION <= 50100 || __VINEYARD_GCC_VERSION >= 70200)
return ctti::nameof<T>().cppstring();
#else
#if defined(__VINEYARD_GCC_VERSION) && __VINEYARD_GCC_VERSION <= 90100
return __typename_from_function<T>();
#else
return ctti::nameof<T>().cppstring();
#endif
}

template <template <typename...> class C, typename... Args>
inline const std::string typename_impl(C<Args...> const&) {
#if defined(__VINEYARD_GCC_VERSION) && \
(__VINEYARD_GCC_VERSION <= 50100 || __VINEYARD_GCC_VERSION >= 70200)
#if defined(__VINEYARD_GCC_VERSION) && __VINEYARD_GCC_VERSION <= 90100
const auto fullname = __typename_from_function<C<Args...>>();
const auto index = fullname.find('<');
if (index == std::string::npos) {
return fullname;
}
const auto class_name = fullname.substr(0, index);
return class_name + "<" + typename_unpack_args<Args...>() + ">";
#else
constexpr auto fullname = ctti::pretty_function::type<C<Args...>>();
constexpr const char* index = ctti::detail::find(fullname, "<");
if (index == fullname.end()) {
Expand All @@ -102,14 +107,6 @@ inline const std::string typename_impl(C<Args...> const&) {
constexpr auto class_name =
fullname(CTTI_VALUE_PRETTY_FUNCTION_LEFT - 1, index - fullname.begin());
return class_name.cppstring() + "<" + typename_unpack_args<Args...>() + ">";
#else
const auto fullname = __typename_from_function<C<Args...>>();
const auto index = fullname.find('<');
if (index == std::string::npos) {
return fullname;
}
const auto class_name = fullname.substr(0, index);
return class_name + "<" + typename_unpack_args<Args...>() + ">";
#endif
}

Expand Down

0 comments on commit aefdac4

Please sign in to comment.