From 841b6070ade8ba35ff4a5d01cdd3c99293ed9dcb Mon Sep 17 00:00:00 2001 From: zzyyyl Date: Fri, 26 Aug 2022 01:36:22 +0800 Subject: [PATCH] fix: fix some of the compilation errors #1666 fix https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/1666 Co-authored-by: Horror Proton <107091537+horror-proton@users.noreply.github.com> --- 3rdparty/include/meojson/json.hpp | 7 ++++++- src/MeoAssistant/AsstUtils.hpp | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/3rdparty/include/meojson/json.hpp b/3rdparty/include/meojson/json.hpp index 07ae06c42a..dc18989d31 100644 --- a/3rdparty/include/meojson/json.hpp +++ b/3rdparty/include/meojson/json.hpp @@ -321,7 +321,7 @@ namespace json bool empty() const noexcept { return _object_data.empty(); } size_t size() const noexcept { return _object_data.size(); } - bool contains(const std::string& key) const { return _object_data.find(key) != _object_data.cend(); } + bool contains(const std::string& key) const; bool exists(const std::string& key) const { return contains(key); } const value& at(const std::string& key) const; const std::string to_string() const; @@ -1484,6 +1484,11 @@ namespace json ; } + MEOJSON_INLINE bool object::contains(const std::string& key) const + { + return _object_data.find(key) != _object_data.cend(); + } + MEOJSON_INLINE const value& object::at(const std::string& key) const { return _object_data.at(key); diff --git a/src/MeoAssistant/AsstUtils.hpp b/src/MeoAssistant/AsstUtils.hpp index eba47083bf..a36d67cbed 100644 --- a/src/MeoAssistant/AsstUtils.hpp +++ b/src/MeoAssistant/AsstUtils.hpp @@ -19,6 +19,12 @@ namespace asst::utils { + // delete instantiation of template with message, when static_assert(false, Message) does not work + #define ASST_STATIC_ASSERT_FALSE(Message, ...) \ + static_assert(::asst::utils::integral_constant_at_template_instantiation::value, Message) + template + struct integral_constant_at_template_instantiation : std::integral_constant {}; + inline void _string_replace_all(std::string& str, const std::string_view& old_value, const std::string_view& new_value) { for (std::string::size_type pos(0); pos != std::string::npos; pos += new_value.length()) { @@ -157,6 +163,7 @@ namespace asst::utils #endif } + template inline std::string utf8_to_unicode_escape(const std::string& utf8_str) { #ifdef _WIN32 @@ -188,7 +195,8 @@ namespace asst::utils return unicode_escape_str; #else - static_assert(false, "Don't use utf8_to_unicode_escape in non-win32."); + ASST_STATIC_ASSERT_FALSE("Workaround for windows, not implemented in other OS yet.", _); + return utf8_str; #endif } @@ -368,11 +376,5 @@ namespace asst::utils // } // return str; //} - - template - struct integral_constant_at_template_instantiation : std::integral_constant {}; } -// delete instantiation of template with message, when static_assert(false, Message) does not work -#define ASST_STATIC_ASSERT_FALSE(Message, ...) \ -static_assert(::asst::utils::integral_constant_at_template_instantiation::value, Message)