Skip to content

Instantly share code, notes, and snippets.

@talybin
Last active August 5, 2021 23:48
Show Gist options
  • Save talybin/eabc1fb9bc20c3838dc270fee9f9de13 to your computer and use it in GitHub Desktop.
Save talybin/eabc1fb9bc20c3838dc270fee9f9de13 to your computer and use it in GitHub Desktop.
The type of inner struct.
#include <iostream>
#include <string_view>
template <class T>
constexpr std::string_view type_name(const T&)
{
std::string_view sv = __PRETTY_FUNCTION__;
sv.remove_prefix(sv.find('=') + 2);
return { sv.data(), sv.find(';') };
}
auto test()
{
struct inner { };
return inner();
};
int main()
{
// Type of inner struct ...
std::cout << type_name(test()) << '\n';
// ... compared to type of lambda
auto f = []{ };
std::cout << type_name(f) << '\n';
}
@talybin
Copy link
Author

talybin commented Aug 4, 2021

Output

test()::inner
main()::<lambda()>

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