update example
This commit is contained in:
parent
bc88d7d613
commit
0bc3e1d0c7
1 changed files with 31 additions and 33 deletions
|
@ -90,58 +90,56 @@ int main() {
|
||||||
|
|
||||||
// Nameof enum variable.
|
// Nameof enum variable.
|
||||||
auto color = Color::RED;
|
auto color = Color::RED;
|
||||||
std::cout << nameof::nameof_enum(color) << std::endl; // RED
|
std::cout << nameof::nameof_enum(color) << std::endl; // 'RED'
|
||||||
std::cout << NAMEOF_ENUM(color) << std::endl; // RED
|
std::cout << NAMEOF_ENUM(color) << std::endl; // 'RED'
|
||||||
|
|
||||||
// Nameof static storage enum variable.
|
// Nameof static storage enum variable.
|
||||||
constexpr auto const_color = Color::BLUE;
|
constexpr auto const_color = Color::BLUE;
|
||||||
std::cout << nameof::nameof_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
|
std::cout << NAMEOF_CONST_ENUM(const_color) << std::endl; // 'BLUE'
|
||||||
|
|
||||||
// Nameof.
|
// Nameof.
|
||||||
std::cout << NAMEOF(structvar) << std::endl; // structvar
|
std::cout << NAMEOF(structvar) << std::endl; // 'structvar'
|
||||||
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((&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(othervar.ll.field) << std::endl; // 'field'
|
||||||
std::cout << NAMEOF(ptrvar) << std::endl; // 'ptrvar'
|
std::cout << NAMEOF(ptrvar) << std::endl; // 'ptrvar
|
||||||
|
|
||||||
// Nameof function.
|
// Nameof function.
|
||||||
std::cout << NAMEOF(&SomeStruct::SomeMethod1) << std::endl; // SomeMethod1
|
std::cout << NAMEOF(&SomeStruct::SomeMethod1) << std::endl; // 'SomeMethod1'
|
||||||
std::cout << NAMEOF(structvar.SomeMethod2()) << std::endl; // SomeMethod2
|
std::cout << NAMEOF(structvar.SomeMethod2()) << std::endl; // 'SomeMethod2'
|
||||||
std::cout << NAMEOF(SomeMethod3) << std::endl; // SomeMethod3
|
std::cout << NAMEOF(SomeMethod3) << std::endl; // 'SomeMethod3'
|
||||||
std::cout << NAMEOF(SomeMethod4<int, float>(1.0f)) << std::endl; // SomeMethod4
|
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>::SomeMethod5) << std::endl; // SomeMethod5
|
std::cout << NAMEOF(&SomeClass<int>::SomeMethod6<long int>) << std::endl; // 'SomeMethod6'
|
||||||
std::cout << NAMEOF(&SomeClass<int>::SomeMethod6<long int>) << std::endl; // SomeMethod6
|
|
||||||
|
|
||||||
// Nameof with template suffix.
|
// Nameof with template suffix.
|
||||||
std::cout << NAMEOF_FULL(SomeMethod4<int, float>) << std::endl; // SomeMethod4<int, float>
|
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(&SomeClass<int>::SomeMethod6<long int>) << std::endl; // 'SomeMethod6<long int>'
|
||||||
|
|
||||||
// Nameof variable type.
|
// Nameof variable type.
|
||||||
std::cout << nameof::nameof_type<decltype(structvar)>() << std::endl; // SomeStruct
|
std::cout << nameof::nameof_type<decltype(structvar)>() << std::endl; // 'SomeStruct'
|
||||||
std::cout << NAMEOF_VAR_TYPE(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(SomeClass<int>{}) << std::endl; // 'SomeClass<int>'
|
||||||
std::cout << NAMEOF_VAR_TYPE(othervar.ll) << std::endl; // Long::LL
|
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> &&
|
|
||||||
|
|
||||||
// Nameof type.
|
// Nameof type.
|
||||||
std::cout << nameof::nameof_type<SomeClass<int>>() << std::endl; // SomeClass<int>
|
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_TYPE(SomeClass<int>) << std::endl; // SomeClass<int>
|
std::cout << NAMEOF_TYPE(Long::LL) << std::endl; // 'Long::LL'
|
||||||
|
|
||||||
// Nameof macro.
|
// Nameof macro.
|
||||||
std::cout << NAMEOF(__LINE__) << std::endl; // __LINE__
|
std::cout << NAMEOF(__LINE__) << std::endl; // '__LINE__'
|
||||||
std::cout << NAMEOF(NAMEOF(structvar)) << std::endl; // 'NAMEOF'
|
std::cout << NAMEOF(NAMEOF(structvar)) << std::endl; // 'NAMEOF'
|
||||||
|
|
||||||
// Nameof raw.
|
// Nameof raw.
|
||||||
std::cout << NAMEOF_RAW(structvar.somefield) << std::endl; // structvar.somefield
|
std::cout << NAMEOF_RAW(structvar.somefield) << std::endl; // 'structvar.somefield'
|
||||||
std::cout << NAMEOF_RAW(&SomeStruct::SomeMethod1) << std::endl; // &SomeStruct::SomeMethod1
|
std::cout << NAMEOF_RAW(&SomeStruct::SomeMethod1) << std::endl; // '&SomeStruct::SomeMethod1'
|
||||||
|
|
||||||
// Some more complex example.
|
// 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 {
|
const auto div = [](int x, int y) -> int {
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
|
@ -154,7 +152,7 @@ int main() {
|
||||||
const int z = div(10, 0);
|
const int z = div(10, 0);
|
||||||
std::cout << z << std::endl;
|
std::cout << z << std::endl;
|
||||||
} catch (const std::exception& e) {
|
} 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 */
|
/* Remarks */
|
||||||
|
|
Loading…
Reference in a new issue