Chatterino
TypeName.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string_view>
4 
5 namespace chatterino {
6 
7 // Adapted from: https://stackoverflow.com/a/56766138.
8 // NOTE: Relies on the "magic" prefixes and suffixes. There are implementations
9 // that attempt to manually detect these (linked in the SO answer above) but
10 // they seemed too complex for the scope we have here.
11 template <typename T>
12 constexpr auto type_name()
13 {
14  std::string_view name, prefix, suffix;
15 #ifdef __clang__
16  name = __PRETTY_FUNCTION__;
17  prefix = "auto chatterino::type_name() [T = ";
18  suffix = "]";
19 #elif defined(__GNUC__)
20  name = __PRETTY_FUNCTION__;
21  prefix = "constexpr auto chatterino::type_name() [with T = ";
22  suffix = "]";
23 #elif defined(_MSC_VER)
24  name = __FUNCSIG__;
25  prefix = "auto __cdecl chatterino::type_name<";
26  suffix = ">(void)";
27 #endif
28  name.remove_prefix(prefix.size());
29  name.remove_suffix(suffix.size());
30 
31  return name;
32 }
33 
34 } // namespace chatterino
Definition: Application.cpp:48
constexpr auto type_name()
Definition: TypeName.hpp:12
QString name
Definition: Credentials.cpp:94