From 25fcbbeb8621e151a0fc8502941d243ba3f3554a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=B6ller?= Date: Thu, 25 Jul 2024 19:00:04 +0200 Subject: [PATCH] removes c++17 deprecation warnings --- include/vdf_parser.hpp | 31 +++++++++++-------------------- tests/CMakeLists.txt | 1 - 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/include/vdf_parser.hpp b/include/vdf_parser.hpp index c3e2db7..da65dbf 100644 --- a/include/vdf_parser.hpp +++ b/include/vdf_parser.hpp @@ -38,7 +38,7 @@ #include // for wstring support -#include +#include #include // internal @@ -105,24 +105,15 @@ template <> struct literal_macro_help inline std::string string_converter(const std::string &w) NOEXCEPT { return w; } -// utility wrapper to adapt locale-bound facets for wstring/wbuffer convert -// from cppreference -template struct deletable_facet : Facet +inline std::string string_converter(const std::wstring &w) NOEXCEPT { - template - deletable_facet(Args &&...args) : Facet(std::forward(args)...) - { - } - ~deletable_facet() {} -}; - -inline std::string -string_converter(const std::wstring &w) // todo: use us-locale -{ - std::wstring_convert< - deletable_facet>> - conv1; - return conv1.to_bytes(w); + std::mbstate_t state = std::mbstate_t(); + auto wstr = w.data(); + std::size_t len = 1 + std::wcsrtombs(nullptr, &wstr, 0, &state); + std::string mbstr(len, '\0'); + // unsafe: ignores any error handling + std::wcsrtombs(&mbstr[0], &wstr, mbstr.size(), &state); + return mbstr; } /////////////////////////////////////////////////////////////////////////// @@ -717,7 +708,7 @@ OutputT read(IterT first, const IterT last, bool *ok, template inline auto read(IterT first, const IterT last, bool *ok, const Options &opt = Options{}) NOEXCEPT - ->basic_object::value_type> + -> basic_object::value_type> { return read::value_type>>( first, last, ok, opt); @@ -726,7 +717,7 @@ inline auto read(IterT first, const IterT last, bool *ok, template inline auto read(IterT first, IterT last, std::error_code &ec, const Options &opt = Options{}) NOEXCEPT - ->basic_object::value_type> + -> basic_object::value_type> { return read::value_type>>( first, last, ec, opt); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 549dc50..97bdc36 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,7 +9,6 @@ add_executable(tests ${SRCS}) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT tests) #requires cmake 3.6 set_property(TARGET tests PROPERTY COMPILE_WARNING_AS_ERROR ON) add_definitions("-DSOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"" "-DCATCH_AMALGAMATED_CUSTOM_MAIN") -target_compile_definitions(tests PRIVATE "-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS" "-D_LIBCPP_DISABLE_DEPRECATION_WARNINGS") target_compile_features(tests PUBLIC cxx_std_17) target_link_libraries(tests PRIVATE ValveFileVDF)