Skip to content

Instantly share code, notes, and snippets.

@SteveBronder
Last active April 15, 2020 17:48
Show Gist options
  • Save SteveBronder/7f1c36280408cd201afe59ed0ab2499a to your computer and use it in GitHub Desktop.
Save SteveBronder/7f1c36280408cd201afe59ed0ab2499a to your computer and use it in GitHub Desktop.
struct Arg {};
// Base class for RVO checking
struct S {
S() { puts("\t\tDefault Constructor");}
S(Arg) { puts("\t\tValue Constructor");}
explicit S(int) {puts("\t\tExplicit Value Constructor (1)");}
explicit S(int, int) { puts("\t\tExplicit Value Constructor (2)");}
~S() { puts("\t\tDestruct");}
S(const S&) { puts("\t\tCopy construct");}
S(S&&) {puts("\t\tMove construct");}
S& operator=(const S&) {puts("\t\tCopy Assign"); return *this;}
S& operator=(S&&) {puts("\t\tMove Assign"); return *this;}
};
#include <string_view>
template <typename T>
constexpr std::string_view
type_name()
{
std::string_view name, prefix, suffix;
#ifdef __clang__
name = __PRETTY_FUNCTION__;
prefix = "std::string_view type_name() [T = ";
suffix = "]";
#elif defined(__GNUC__)
name = __PRETTY_FUNCTION__;
prefix = "constexpr std::string_view type_name() [with T = ";
suffix = "; std::string_view = std::basic_string_view<char>]";
#elif defined(_MSC_VER)
name = __FUNCSIG__;
prefix = "class std::basic_string_view<char,struct std::char_traits<char> > __cdecl type_name<";
suffix = ">(void)";
#endif
name.remove_prefix(prefix.size());
name.remove_suffix(suffix.size());
return name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment