From ad59562c9ec43f5b0da9f917dc0f168a1697d0b2 Mon Sep 17 00:00:00 2001 From: Neargye Date: Thu, 12 Dec 2019 20:11:51 +0500 Subject: [PATCH] update example --- example/example.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 9caade4..79f7415 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -41,7 +41,7 @@ void SomeMethod3() { template std::string SomeMethod4(U value) { - auto function_name = std::string{NAMEOF(SomeMethod4)} + auto function_name = NAMEOF(SomeMethod4).str() .append("<") .append(NAMEOF_TYPE(T)) .append(", ") @@ -102,9 +102,15 @@ int main() { static_assert("structvar"sv == name); name_to_chars(name.c_str()); // 'structvar' + // or name_to_chars(name.data()); // Note: c_str() return name as null-terminated C string, no memory allocation. + name_to_string(name.str()); // 'structvar' // Note: str() occure memory allocation to copy name to std::string. + // or name_to_string(std::string{name}); + // or name_to_string(static_cast(name)); + // Note: cast to std::string occure memory allocation to copy name to std::string. + name_to_string_view(name); // 'structvar' // Note: Implicit cast to std::string_view, no memory allocation. @@ -161,7 +167,7 @@ int main() { auto div = [](int x, int y) -> int { if (y == 0) { - throw std::invalid_argument(std::string{NAMEOF(y)} + " should not be zero!"); + throw std::invalid_argument(NAMEOF(y).str() + " should not be zero!"); } return x / y; };