update readme
This commit is contained in:
parent
096b86e1fa
commit
85929c66b1
2 changed files with 15 additions and 14 deletions
23
README.md
23
README.md
|
@ -36,7 +36,6 @@ Before, you had to use string literals to refer to definitions, which is brittle
|
||||||
## [Examples](example/example.cpp)
|
## [Examples](example/example.cpp)
|
||||||
|
|
||||||
* Name of variable and member
|
* Name of variable and member
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// Name of variable
|
// Name of variable
|
||||||
NAMEOF(somevar) -> "somevar"
|
NAMEOF(somevar) -> "somevar"
|
||||||
|
@ -47,8 +46,7 @@ constexpr auto cx_name = NAMEOF(somevar);
|
||||||
static_assert("somevar" == cx_name);
|
static_assert("somevar" == cx_name);
|
||||||
```
|
```
|
||||||
|
|
||||||
* Name of of function
|
* Name of function
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// Name of function
|
// Name of function
|
||||||
NAMEOF(some_method<int, float>) -> "some_method"
|
NAMEOF(some_method<int, float>) -> "some_method"
|
||||||
|
@ -60,37 +58,35 @@ NAMEOF(somevar.boo<int>() -> "boo<int>"
|
||||||
constexpr auto cx_name = NAMEOF(somevar.foo());
|
constexpr auto cx_name = NAMEOF(somevar.foo());
|
||||||
static_assert("foo" == cx_name);
|
static_assert("foo" == cx_name);
|
||||||
```
|
```
|
||||||
* Name of of enum
|
|
||||||
|
|
||||||
|
* Name of enum
|
||||||
```cpp
|
```cpp
|
||||||
// Name of enum
|
// Name of enum
|
||||||
const auto c = Color::RED;
|
const auto c = Color::RED;
|
||||||
NAMEOF_ENUM(c) -> "RED"
|
NAMEOF_ENUM(c) -> "RED"
|
||||||
// Name of enum function
|
// Name of enum function
|
||||||
nameof::NameofEnum(c) -> "RED"
|
nameof::nameof_enum(c) -> "RED"
|
||||||
|
|
||||||
constexpr auto cx_name = NAMEOF_ENUM(c);
|
constexpr auto cx_name = NAMEOF_ENUM(c);
|
||||||
static_assert("RED" == cx_name);
|
static_assert("RED" == cx_name);
|
||||||
```
|
```
|
||||||
|
|
||||||
* Name of type
|
* Name of type
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// Name of variable type
|
// Name of variable type
|
||||||
NAMEOF_TYPE(Color::RED) -> "Color"
|
NAMEOF_TYPE(Color::RED) -> "Color"
|
||||||
// Name of type
|
// Name of type
|
||||||
NAMEOF_TYPE_T(int) -> "int"
|
NAMEOF_TYPE_T(int) -> "int"
|
||||||
// Name of variable type function
|
// Name of variable type function
|
||||||
nameof::NameofType(Color::RED) -> "Color"
|
nameof::nameof_type(Color::RED) -> "Color"
|
||||||
// Name of type function
|
// Name of type function
|
||||||
nameof::NameofType<int> -> "int"
|
nameof::nameof_type<int> -> "int"
|
||||||
|
|
||||||
constexpr auto cx_name = NAMEOF_TYPE(Color::RED);
|
constexpr auto cx_name = NAMEOF_TYPE(Color::RED);
|
||||||
static_assert("Color" == cx_name);
|
static_assert("Color" == cx_name);
|
||||||
```
|
```
|
||||||
|
|
||||||
* Name of macros
|
* Name of macros
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
NAMEOF(__LINE__) -> "__LINE__"
|
NAMEOF(__LINE__) -> "__LINE__"
|
||||||
|
|
||||||
|
@ -105,14 +101,19 @@ static_assert("__LINE__" == cx_name);
|
||||||
* The argument expression identifies a code definition, but it is never evaluated.
|
* The argument expression identifies a code definition, but it is never evaluated.
|
||||||
|
|
||||||
* If you need raw fully-qualified name, use NAMEOF_RAW.
|
* If you need raw fully-qualified name, use NAMEOF_RAW.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
NAMEOF_RAW(somevar.somefield) -> "somevar.somefield"
|
NAMEOF_RAW(somevar.somefield) -> "somevar.somefield"
|
||||||
NAMEOF_RAW(&SomeStruct::SomeMethod) -> "&SomeStruct::SomeMethod"
|
NAMEOF_RAW(&SomeStruct::SomeMethod) -> "&SomeStruct::SomeMethod"
|
||||||
```
|
```
|
||||||
|
|
||||||
* Spaces and Tabs ignored
|
* NAMEOF_ENUM does not work on the GCC.
|
||||||
|
```cpp
|
||||||
|
auto c = Color::RED;
|
||||||
|
NAMEOF_ENUM(c) -> "(Color)0"
|
||||||
|
nameof::nameof_enum(c) -> "(Color)0"
|
||||||
|
```
|
||||||
|
|
||||||
|
* Spaces and Tabs ignored
|
||||||
```cpp
|
```cpp
|
||||||
NAMEOF( somevar ) -> "somevar"
|
NAMEOF( somevar ) -> "somevar"
|
||||||
NAMEOF( somevar ) -> "somevar"
|
NAMEOF( somevar ) -> "somevar"
|
||||||
|
|
|
@ -92,9 +92,9 @@ Long othervar;
|
||||||
SomeStruct* ptrvar = &structvar;
|
SomeStruct* ptrvar = &structvar;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Compile-time nameof.
|
// Compile-time.
|
||||||
constexpr auto constexpr_work_fine = NAMEOF(structvar);
|
constexpr auto cx_name = NAMEOF(structvar);
|
||||||
static_assert("structvar" == constexpr_work_fine);
|
static_assert("structvar" == cx_name);
|
||||||
|
|
||||||
// Enum name.
|
// Enum name.
|
||||||
std::cout << NAMEOF(Color::RED) << std::endl; // RED
|
std::cout << NAMEOF(Color::RED) << std::endl; // RED
|
||||||
|
|
Loading…
Reference in a new issue