change to_string() to str()

This commit is contained in:
neargye 2019-10-25 15:33:53 +05:00
parent f5a2489330
commit dec2c332bd
2 changed files with 3 additions and 5 deletions

View file

@ -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.

View file

@ -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 Char = char, typename Traits = std::char_traits<Char>, typename Allocator = std::allocator<Char>>
[[nodiscard]] std::basic_string<Char, Traits, Allocator> to_string() const { return {begin(), end()}; }
[[nodiscard]] std::basic_string<Char, Traits, Allocator> str() const { return {begin(), end()}; }
[[nodiscard]] constexpr operator std::string_view() const noexcept { return {data(), size()}; }