From c61a1784ec75c34a3fe081f89434ec08af332239 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 8 Feb 2021 22:53:38 +0100 Subject: [PATCH] Allow using splitStringSimple() with `std::unordered_set` in C++20 * So one could use e.g. `std::unordered_set` as target container when splitting an `std::string_view`. * Still an experimental feature --- CMakeLists.txt | 2 +- conversion/stringconversion.h | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24c787c..da33ec8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,7 +114,7 @@ set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parse set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local) set(META_VERSION_MAJOR 5) set(META_VERSION_MINOR 10) -set(META_VERSION_PATCH 1) +set(META_VERSION_PATCH 2) # find required 3rd party libraries include(3rdParty) diff --git a/conversion/stringconversion.h b/conversion/stringconversion.h index d6357b0..8671ffe 100644 --- a/conversion/stringconversion.h +++ b/conversion/stringconversion.h @@ -194,7 +194,15 @@ Container splitStringSimple(const typename Container::value_type &string, const if (delimPos == Container::value_type::npos) { delimPos = string.size(); } - res.emplace_back(string.substr(i, delimPos - i)); +#if __cplusplus >= 202002 + if constexpr (requires { res.emplace_back(string); }) { +#endif + res.emplace_back(string.substr(i, delimPos - i)); +#if __cplusplus >= 202002 + } else { + res.emplace(string.substr(i, delimPos - i)); + } +#endif } return res; }