From f0c2d7c5394dd8e40a9ff7c4af1f57a55c8d8886 Mon Sep 17 00:00:00 2001 From: neargye Date: Wed, 9 Oct 2019 22:48:06 +0500 Subject: [PATCH] update example --- example/example.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/example/example.cpp b/example/example.cpp index 101611b..d65b933 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -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;