Last active
August 5, 2021 23:48
-
-
Save talybin/eabc1fb9bc20c3838dc270fee9f9de13 to your computer and use it in GitHub Desktop.
The type of inner struct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output