From cc8a5988256896b1bd199f760553517ca6a76a58 Mon Sep 17 00:00:00 2001 From: terik23 Date: Sat, 17 Mar 2018 10:15:00 +0500 Subject: [PATCH] Update README --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7d774ed..06147a3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # nameof(x) c++ +C++ alternative to [nameOf](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/nameof) operator. + Simple Example: ``` #include -#include #include + struct SomeStruct { int SomeField; void SomeMethod() { std::cout << "No called!" << std::endl; } @@ -15,13 +17,13 @@ int someVar = 0; int main() { SomeStruct someVar{1}; - constexpr auto a = nameof_variable(someVar.SomeField); - constexpr auto b = nameof_variable((&someVar)->SomeField); - constexpr auto c = nameof_variable(someVar); - constexpr auto d = nameof_variable(::someVar); - constexpr auto e = nameof_variable(&SomeStruct::SomeMethod); - constexpr auto f = nameof_function(someVar.SomeMethod()); - constexpr auto g = nameof_type(SomeStruct); + constexpr auto a = NAMEOF_VAR(someVar.SomeField); + constexpr auto b = NAMEOF_VAR((&someVar)->SomeField); + constexpr auto c = NAMEOF_VAR(someVar); + constexpr auto d = NAMEOF_VAR(::someVar); + constexpr auto e = NAMEOF_VAR(&SomeStruct::SomeMethod); + constexpr auto f = NAMEOF_FUN(someVar.SomeMethod()); + constexpr auto g = NAMEOF_TYPE(SomeStruct); std::cout << a << std::endl; // SomeField std::cout << b << std::endl; // SomeField