diff --git a/example/example.cpp b/example/example.cpp index e68985b..399e2ac 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -57,7 +57,7 @@ std::string SomeMethod4(U value) { template class SomeClass { -public: + public: void SomeMethod5() const { std::cout << nameof::nameof_type() << 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() << std::endl; // BLUE - std::cout << NAMEOF_CONST_ENUM(const_color) << std::endl; // BLUE + std::cout << nameof::nameof_enum() << 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(1.0f)) << std::endl; // SomeMethod4 - std::cout << NAMEOF(SomeMethod4) << std::endl; // SomeMethod4 - std::cout << NAMEOF(&SomeClass::SomeMethod5) << std::endl; // SomeMethod5 - std::cout << NAMEOF(&SomeClass::SomeMethod6) << 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(1.0f)) << std::endl; // 'SomeMethod4' + std::cout << NAMEOF(&SomeClass::SomeMethod5) << std::endl; // 'SomeMethod5' + std::cout << NAMEOF(&SomeClass::SomeMethod6) << std::endl; // 'SomeMethod6' // Nameof with template suffix. - std::cout << NAMEOF_FULL(SomeMethod4) << std::endl; // SomeMethod4 - std::cout << NAMEOF_FULL(&SomeClass::SomeMethod6) << std::endl; // SomeMethod6 + std::cout << NAMEOF_FULL(SomeMethod4) << std::endl; // 'SomeMethod4' + std::cout << NAMEOF_FULL(&SomeClass::SomeMethod6) << std::endl; // 'SomeMethod6' // Nameof variable type. - std::cout << nameof::nameof_type() << std::endl; // SomeStruct - std::cout << NAMEOF_VAR_TYPE(structvar) << std::endl; // SomeStruct - std::cout << NAMEOF_VAR_TYPE(SomeClass{}) << std::endl; // SomeClass - std::cout << NAMEOF_VAR_TYPE(othervar.ll) << std::endl; // Long::LL - std::cout << NAMEOF_VAR_TYPE(std::declval>()) << std::endl; // const SomeClass && + std::cout << nameof::nameof_type() << std::endl; // 'SomeStruct' + std::cout << NAMEOF_VAR_TYPE(structvar) << std::endl; // 'SomeStruct' + std::cout << NAMEOF_VAR_TYPE(SomeClass{}) << std::endl; // 'SomeClass' + std::cout << NAMEOF_VAR_TYPE(othervar.ll) << std::endl; // 'Long::LL' // Nameof type. - std::cout << nameof::nameof_type>() << std::endl; // SomeClass - std::cout << NAMEOF_TYPE(const SomeClass volatile *) << std::endl; // const volatile SomeClass * - std::cout << NAMEOF_TYPE(SomeClass) << std::endl; // SomeClass + std::cout << nameof::nameof_type>() << std::endl; // 'SomeClass' + std::cout << NAMEOF_TYPE(SomeClass) << std::endl; // 'SomeClass' + 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(structvar) << std::endl; // SomeMethod4(SomeStruct value) + std::cout << SomeMethod4(structvar) << std::endl; // 'SomeMethod4(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 */