Skip to content

Commit

Permalink
removes c++17 deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyTinni committed Jul 25, 2024
1 parent 1a132f3 commit 25fcbbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
31 changes: 11 additions & 20 deletions include/vdf_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <system_error>

// for wstring support
#include <locale>
#include <cwchar>
#include <string>

// internal
Expand Down Expand Up @@ -105,24 +105,15 @@ template <> struct literal_macro_help<wchar_t>

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 <class Facet> struct deletable_facet : Facet
inline std::string string_converter(const std::wstring &w) NOEXCEPT
{
template <class... Args>
deletable_facet(Args &&...args) : Facet(std::forward<Args>(args)...)
{
}
~deletable_facet() {}
};

inline std::string
string_converter(const std::wstring &w) // todo: use us-locale
{
std::wstring_convert<
deletable_facet<std::codecvt<wchar_t, char, std::mbstate_t>>>
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;
}

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -717,7 +708,7 @@ OutputT read(IterT first, const IterT last, bool *ok,
template <typename IterT>
inline auto read(IterT first, const IterT last, bool *ok,
const Options &opt = Options{}) NOEXCEPT
->basic_object<typename std::iterator_traits<IterT>::value_type>
-> basic_object<typename std::iterator_traits<IterT>::value_type>
{
return read<basic_object<typename std::iterator_traits<IterT>::value_type>>(
first, last, ok, opt);
Expand All @@ -726,7 +717,7 @@ inline auto read(IterT first, const IterT last, bool *ok,
template <typename IterT>
inline auto read(IterT first, IterT last, std::error_code &ec,
const Options &opt = Options{}) NOEXCEPT
->basic_object<typename std::iterator_traits<IterT>::value_type>
-> basic_object<typename std::iterator_traits<IterT>::value_type>
{
return read<basic_object<typename std::iterator_traits<IterT>::value_type>>(
first, last, ec, opt);
Expand Down
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 25fcbbe

Please sign in to comment.