From dec2c332bdba4522625303abadbba5a75e563989 Mon Sep 17 00:00:00 2001 From: neargye Date: Fri, 25 Oct 2019 15:33:53 +0500 Subject: [PATCH] change to_string() to str() --- example/example.cpp | 4 ++-- include/nameof.hpp | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index c28a6a8..9caade4 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -103,8 +103,8 @@ int main() { name_to_chars(name.c_str()); // 'structvar' // Note: c_str() return name as null-terminated C string, no memory allocation. - name_to_string(name.to_string()); // 'structvar' - // Note: to_string() occure memory allocation to copy name to std::string. + name_to_string(name.str()); // 'structvar' + // Note: str() 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. diff --git a/include/nameof.hpp b/include/nameof.hpp index 9b8ac24..eb4d79d 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -162,12 +162,10 @@ class [[nodiscard]] cstring { return std::string_view{data(), size()}.compare(str); } - [[nodiscard]] constexpr std::string_view to_string_view() const noexcept { return {data(), size()}; } - [[nodiscard]] constexpr const char* c_str() const noexcept { return data(); } template, typename Allocator = std::allocator> - [[nodiscard]] std::basic_string to_string() const { return {begin(), end()}; } + [[nodiscard]] std::basic_string str() const { return {begin(), end()}; } [[nodiscard]] constexpr operator std::string_view() const noexcept { return {data(), size()}; }