update example
This commit is contained in:
parent
0414495682
commit
f0c2d7c539
1 changed files with 16 additions and 0 deletions
|
@ -83,11 +83,27 @@ SomeStruct structvar;
|
|||
Long othervar;
|
||||
SomeStruct* ptrvar = &structvar;
|
||||
|
||||
void name_to_str(const char* name) {
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
|
||||
void name_to_string(const std::string& name) {
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
|
||||
void name_to_string_view(std::string_view name) {
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Compile-time.
|
||||
constexpr auto name = NAMEOF(structvar);
|
||||
static_assert("structvar" == name);
|
||||
|
||||
name_to_str(name.data()); // 'structvar'
|
||||
name_to_string(std::string{name}); // 'structvar'
|
||||
name_to_string_view(name); // 'structvar'
|
||||
|
||||
#if defined(NAMEOF_ENUM_SUPPORTED)
|
||||
// Nameof enum variable.
|
||||
auto color = Color::RED;
|
||||
|
|
Loading…
Reference in a new issue