Skip to content

Instantly share code, notes, and snippets.

@talybin
Last active August 18, 2021 09:37
Show Gist options
  • Save talybin/e4a94aa9c94b09dd766b4510c8cf7c69 to your computer and use it in GitHub Desktop.
Save talybin/e4a94aa9c94b09dd766b4510c8cf7c69 to your computer and use it in GitHub Desktop.
Type name revisited. This generates only actual type of name in output binary.
#pragma once
#include <utility>
template <class T, std::size_t... I>
inline const char* type_name(std::index_sequence<I...>) {
static constexpr char name[] = { __PRETTY_FUNCTION__[I + 60]..., 0 };
return name;
}
template <class T>
inline const char* type_name() {
return type_name<T>(
std::make_index_sequence<sizeof(__PRETTY_FUNCTION__) - 36>());
}
template <class T>
inline const char* type_name(const T&) {
return type_name<T>();
}
@talybin
Copy link
Author

talybin commented Aug 6, 2021

Result can be found here
https://godbolt.org/z/vMTjEvbTz

@talybin
Copy link
Author

talybin commented Aug 6, 2021

Note! Offsets need to be adjusted if signature changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment