From f14c1b50652c20ee7cf90c1221fa2bc289877ea2 Mon Sep 17 00:00:00 2001 From: neargye Date: Sat, 13 Aug 2022 18:28:52 +0400 Subject: [PATCH] fix build --- include/nameof.hpp | 19 ++++++++++--------- test/test_aliases.cpp | 15 +++++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 6610134..2032c3d 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -879,16 +879,16 @@ string nameof_full_type_rtti(const char* tn) { free(dmg); assert(name.size() > 0 && "Type does not have a name."); if constexpr (std::is_const_v>) { - name = "const " + name; + name = string{"const "}.append(name); } if constexpr (std::is_volatile_v>) { - name = "volatile " + name; + name = string{"volatile "}.append(name); } if constexpr (std::is_lvalue_reference_v) { - name += '&'; + name.append(1, '&'); } if constexpr (std::is_rvalue_reference_v) { - name += "&&"; + name.append("&&"); } return name; @@ -898,7 +898,8 @@ template = 0> string nameof_short_type_rtti(const char* tn) { static_assert(nameof_type_rtti_supported::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility)."); const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr); - const auto name = string{pretty_name(dmg)}; + const auto pname = pretty_name(dmg); + const auto name = string{pname.data(), pname.size()}; free(dmg); assert(name.size() > 0 && "Type does not have a short name."); @@ -920,16 +921,16 @@ string nameof_full_type_rtti(const char* tn) noexcept { auto name = string{tn}; assert(name.size() > 0 && "Type does not have a name."); if constexpr (std::is_const_v>) { - name = "const " + name; + name = string{"const "}.append(name); } if constexpr (std::is_volatile_v>) { - name = "volatile " + name; + name = string{"volatile "}.append(name); } if constexpr (std::is_lvalue_reference_v) { - name += '&'; + name.append(1, '&'); } if constexpr (std::is_rvalue_reference_v) { - name += "&&"; + name.append("&&"); } return name; diff --git a/test/test_aliases.cpp b/test/test_aliases.cpp index 354e38c..ed893e0 100644 --- a/test/test_aliases.cpp +++ b/test/test_aliases.cpp @@ -28,14 +28,16 @@ struct MyString { MyString() : str{} {} // required + MyString(const char* s) : str{s} {} // required MyString(const char* s, std::size_t l) : str{s, l} {} // required bool empty() const { return str.empty(); } // required + std::size_t size() const { return str.size(); } // required auto begin() const { return str.begin(); } // required auto end() const { return str.end(); } // required - void append(std::size_t count, char c) { str.append(count, c); } // required - void append(const char* s, std::size_t size) { str.append(s, size); } // required + MyString& append(std::size_t count, char c) { str.append(count, c); return *this; } // required + MyString& append(const char* s) { str.append(s); return *this; } // required + MyString& append(const MyString& s) { str.append(s.str); return *this; } // required - std::size_t size() const { return str.size(); } int compare(const char* s) const { return str.compare(s); } private: @@ -47,7 +49,8 @@ struct MyStringView { static constexpr auto npos = std::string_view::npos; // required constexpr MyStringView() : str{} {} // required - constexpr MyStringView(const char* cstr, std::size_t size) : str{cstr, size} {} // required + constexpr MyStringView(const char* s) : str{s} {} // required + constexpr MyStringView(const char* s, std::size_t size) : str{s, size} {} // required constexpr bool empty() const { return str.empty(); } // required constexpr std::size_t size() const { return str.size(); } // required constexpr const char* data() const { return str.data(); } // required @@ -57,10 +60,10 @@ struct MyStringView { constexpr std::size_t find(char c) const { return str.find(c); } // required constexpr MyStringView substr(std::size_t p, std::size_t n) { return str.substr(p, n); } // required constexpr void remove_prefix(std::size_t n) { str.remove_prefix(n); } // required - constexpr int compare(MyStringView s) const { return str.compare(s); } // required + constexpr void remove_suffix(std::size_t n) { str.remove_suffix(n); } // required + constexpr int compare(MyStringView s) const { return str.compare(s.str); } // required friend constexpr bool operator==(MyStringView lhs, MyStringView rhs); // required - constexpr MyStringView(const char* cstr) : str{ cstr } {} constexpr int compare(const char* s) const { return str.compare(s); } private: