update example

This commit is contained in:
neargye 2019-04-05 19:52:59 +05:00
parent bc88d7d613
commit 0bc3e1d0c7

View file

@ -57,7 +57,7 @@ std::string SomeMethod4(U value) {
template <typename T>
class SomeClass {
public:
public:
void SomeMethod5() const {
std::cout << nameof::nameof_type<T>() << std::endl;
}
@ -90,58 +90,56 @@ int main() {
// Nameof enum variable.
auto color = Color::RED;
std::cout << nameof::nameof_enum(color) << std::endl; // RED
std::cout << NAMEOF_ENUM(color) << std::endl; // RED
std::cout << nameof::nameof_enum(color) << std::endl; // 'RED'
std::cout << NAMEOF_ENUM(color) << std::endl; // 'RED'
// Nameof static storage enum variable.
constexpr auto const_color = Color::BLUE;
std::cout << nameof::nameof_enum<const_color>() << std::endl; // BLUE
std::cout << NAMEOF_CONST_ENUM(const_color) << std::endl; // BLUE
std::cout << nameof::nameof_enum<const_color>() << std::endl; // 'BLUE'
std::cout << NAMEOF_CONST_ENUM(const_color) << std::endl; // 'BLUE'
// Nameof.
std::cout << NAMEOF(structvar) << std::endl; // structvar
std::cout << NAMEOF(::structvar) << std::endl; // structvar
std::cout << NAMEOF(structvar.somefield) << std::endl; // somefield
std::cout << NAMEOF((&structvar)->somefield) << std::endl; // somefield
std::cout << NAMEOF(othervar.ll.field) << std::endl; // field
std::cout << NAMEOF(ptrvar) << std::endl; // 'ptrvar'
std::cout << NAMEOF(structvar) << std::endl; // 'structvar'
std::cout << NAMEOF(::structvar) << std::endl; // 'structvar'
std::cout << NAMEOF(structvar.somefield) << std::endl; // 'somefield'
std::cout << NAMEOF((&structvar)->somefield) << std::endl; // 'somefield'
std::cout << NAMEOF(othervar.ll.field) << std::endl; // 'field'
std::cout << NAMEOF(ptrvar) << std::endl; // 'ptrvar
// Nameof function.
std::cout << NAMEOF(&SomeStruct::SomeMethod1) << std::endl; // SomeMethod1
std::cout << NAMEOF(structvar.SomeMethod2()) << std::endl; // SomeMethod2
std::cout << NAMEOF(SomeMethod3) << std::endl; // SomeMethod3
std::cout << NAMEOF(SomeMethod4<int, float>(1.0f)) << std::endl; // SomeMethod4
std::cout << NAMEOF(SomeMethod4<int, float>) << std::endl; // SomeMethod4
std::cout << NAMEOF(&SomeClass<int>::SomeMethod5) << std::endl; // SomeMethod5
std::cout << NAMEOF(&SomeClass<int>::SomeMethod6<long int>) << std::endl; // SomeMethod6
std::cout << NAMEOF(&SomeStruct::SomeMethod1) << std::endl; // 'SomeMethod1'
std::cout << NAMEOF(structvar.SomeMethod2()) << std::endl; // 'SomeMethod2'
std::cout << NAMEOF(SomeMethod3) << std::endl; // 'SomeMethod3'
std::cout << NAMEOF(SomeMethod4<int, float>(1.0f)) << std::endl; // 'SomeMethod4'
std::cout << NAMEOF(&SomeClass<int>::SomeMethod5) << std::endl; // 'SomeMethod5'
std::cout << NAMEOF(&SomeClass<int>::SomeMethod6<long int>) << std::endl; // 'SomeMethod6'
// Nameof with template suffix.
std::cout << NAMEOF_FULL(SomeMethod4<int, float>) << std::endl; // SomeMethod4<int, float>
std::cout << NAMEOF_FULL(&SomeClass<int>::SomeMethod6<long int>) << std::endl; // SomeMethod6<long int>
std::cout << NAMEOF_FULL(SomeMethod4<int, float>) << std::endl; // 'SomeMethod4<int, float>'
std::cout << NAMEOF_FULL(&SomeClass<int>::SomeMethod6<long int>) << std::endl; // 'SomeMethod6<long int>'
// Nameof variable type.
std::cout << nameof::nameof_type<decltype(structvar)>() << std::endl; // SomeStruct
std::cout << NAMEOF_VAR_TYPE(structvar) << std::endl; // SomeStruct
std::cout << NAMEOF_VAR_TYPE(SomeClass<int>{}) << std::endl; // SomeClass<int>
std::cout << NAMEOF_VAR_TYPE(othervar.ll) << std::endl; // Long::LL
std::cout << NAMEOF_VAR_TYPE(std::declval<const SomeClass<int>>()) << std::endl; // const SomeClass<int> &&
std::cout << nameof::nameof_type<decltype(structvar)>() << std::endl; // 'SomeStruct'
std::cout << NAMEOF_VAR_TYPE(structvar) << std::endl; // 'SomeStruct'
std::cout << NAMEOF_VAR_TYPE(SomeClass<int>{}) << std::endl; // 'SomeClass<int>'
std::cout << NAMEOF_VAR_TYPE(othervar.ll) << std::endl; // 'Long::LL'
// Nameof type.
std::cout << nameof::nameof_type<SomeClass<int>>() << std::endl; // SomeClass<int>
std::cout << NAMEOF_TYPE(const SomeClass<int> volatile *) << std::endl; // const volatile SomeClass<int> *
std::cout << NAMEOF_TYPE(SomeClass<int>) << std::endl; // SomeClass<int>
std::cout << nameof::nameof_type<SomeClass<int>>() << std::endl; // 'SomeClass<int>'
std::cout << NAMEOF_TYPE(SomeClass<int>) << std::endl; // 'SomeClass<int>'
std::cout << NAMEOF_TYPE(Long::LL) << std::endl; // 'Long::LL'
// Nameof macro.
std::cout << NAMEOF(__LINE__) << std::endl; // __LINE__
std::cout << NAMEOF(__LINE__) << std::endl; // '__LINE__'
std::cout << NAMEOF(NAMEOF(structvar)) << std::endl; // 'NAMEOF'
// Nameof raw.
std::cout << NAMEOF_RAW(structvar.somefield) << std::endl; // structvar.somefield
std::cout << NAMEOF_RAW(&SomeStruct::SomeMethod1) << std::endl; // &SomeStruct::SomeMethod1
std::cout << NAMEOF_RAW(structvar.somefield) << std::endl; // 'structvar.somefield'
std::cout << NAMEOF_RAW(&SomeStruct::SomeMethod1) << std::endl; // '&SomeStruct::SomeMethod1'
// Some more complex example.
std::cout << SomeMethod4<int>(structvar) << std::endl; // SomeMethod4<int, SomeStruct>(SomeStruct value)
std::cout << SomeMethod4<int>(structvar) << std::endl; // 'SomeMethod4<int, SomeStruct>(SomeStruct value)'
const auto div = [](int x, int y) -> int {
if (y == 0) {
@ -154,7 +152,7 @@ int main() {
const int z = div(10, 0);
std::cout << z << std::endl;
} catch (const std::exception& e) {
std::cout << e.what() << std::endl; // y should not be zero!
std::cout << e.what() << std::endl; // 'y should not be zero!'
}
/* Remarks */