Update README
This commit is contained in:
parent
1e7ae74d4e
commit
cc8a598825
1 changed files with 10 additions and 8 deletions
18
README.md
18
README.md
|
@ -1,10 +1,12 @@
|
||||||
# nameof(x) c++
|
# nameof(x) c++
|
||||||
|
|
||||||
|
C++ alternative to [nameOf](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/nameof) operator.
|
||||||
|
|
||||||
Simple Example:
|
Simple Example:
|
||||||
```
|
```
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdint>
|
|
||||||
#include <nameof.hpp>
|
#include <nameof.hpp>
|
||||||
|
|
||||||
struct SomeStruct {
|
struct SomeStruct {
|
||||||
int SomeField;
|
int SomeField;
|
||||||
void SomeMethod() { std::cout << "No called!" << std::endl; }
|
void SomeMethod() { std::cout << "No called!" << std::endl; }
|
||||||
|
@ -15,13 +17,13 @@ int someVar = 0;
|
||||||
int main() {
|
int main() {
|
||||||
SomeStruct someVar{1};
|
SomeStruct someVar{1};
|
||||||
|
|
||||||
constexpr auto a = nameof_variable(someVar.SomeField);
|
constexpr auto a = NAMEOF_VAR(someVar.SomeField);
|
||||||
constexpr auto b = nameof_variable((&someVar)->SomeField);
|
constexpr auto b = NAMEOF_VAR((&someVar)->SomeField);
|
||||||
constexpr auto c = nameof_variable(someVar);
|
constexpr auto c = NAMEOF_VAR(someVar);
|
||||||
constexpr auto d = nameof_variable(::someVar);
|
constexpr auto d = NAMEOF_VAR(::someVar);
|
||||||
constexpr auto e = nameof_variable(&SomeStruct::SomeMethod);
|
constexpr auto e = NAMEOF_VAR(&SomeStruct::SomeMethod);
|
||||||
constexpr auto f = nameof_function(someVar.SomeMethod());
|
constexpr auto f = NAMEOF_FUN(someVar.SomeMethod());
|
||||||
constexpr auto g = nameof_type(SomeStruct);
|
constexpr auto g = NAMEOF_TYPE(SomeStruct);
|
||||||
|
|
||||||
std::cout << a << std::endl; // SomeField
|
std::cout << a << std::endl; // SomeField
|
||||||
std::cout << b << std::endl; // SomeField
|
std::cout << b << std::endl; // SomeField
|
||||||
|
|
Loading…
Reference in a new issue