usage of __PRETTY_FUNCTION__ in constexpr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I hope this is the correct place to ask such questions.

I'm using a library that uses __PRETTY_FUNCTION__ in a constexpr to
determine the name of a type at compile time.

Which pretty much looks like this:

template<typename Type>
[[nodiscard]] constexpr auto stripped_type_name() noexcept
{
  std::string_view pretty_function{
    __PRETTY_FUNCTION__
  }; // Results in "constexpr auto stripped_type_name() [with Type =
std::vector<entt::entity>]"
  auto first = pretty_function.find_first_not_of(' ',
pretty_function.find_first_of('=') + 1);
  auto value = pretty_function.substr(first,
pretty_function.find_last_of(']') - first);
  return value;
}

template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
[[nodiscard]] static constexpr std::string_view type_name(int) noexcept
{
  constexpr auto value = stripped_type_name<Type>();
  return value;
}

For me that results in flaky behaviour depending on the compilation
unit, optimization level and various unrelated code changes.
It either returns

"std::vector<entt::entity, std::allocator<entt::entity> >"
or
"std::vector<entt::entity>"

when calling
stripped_type_name<std::vector<entt::entity>>()

I was wondering if this is a proper use of __PRETTY_FUNCTION__ and/or
what could explain such behaviour.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux