diff --git a/docs/sphinx/source/changelog.rst b/docs/sphinx/source/changelog.rst index 8f73e21..7cdcb9e 100644 --- a/docs/sphinx/source/changelog.rst +++ b/docs/sphinx/source/changelog.rst @@ -29,10 +29,6 @@ Changed - Enhanced error handling: ``timezone::from_string()`` returns ``std::optional`` - Simplified API: removed redundant timezone methods (``is_local()``, ``has_offset()``) - Updated documentation to reflect timestamp and timezone APIs -- **Breaking:** ``split()`` now takes its arguments as ``std::string_view`` - instead of ``const std::string&``; callers passing a type that converts - implicitly to ``std::string`` but not to ``std::string_view`` will no - longer compile v0.1.0 - 2024-01-20 ------------------- diff --git a/include/dross/type.h b/include/dross/type.h index 729ae49..47ae1af 100644 --- a/include/dross/type.h +++ b/include/dross/type.h @@ -67,7 +67,6 @@ #include #include -#include #include /** @@ -93,7 +92,7 @@ namespace dross { * // Result: {"a", "b", "c"} * @endcode */ -std::vector split(std::string_view s, std::string_view delimiter); +std::vector split(const std::string& s, const std::string& delimiter); /** * @brief Join string tokens into a single string using a delimiter. diff --git a/src/type.cpp b/src/type.cpp index 9fc1577..b508cb4 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -2,14 +2,21 @@ #include #include +#include namespace dross { -std::vector split(std::string_view s, std::string_view delimiter) +std::vector split(const std::string& s, const std::string& delimiter) { std::vector tokens; - auto range = s | std::views::split(delimiter) | std::views::transform([](auto&& p) { + // Pipe over views rather than over the arguments themselves. On some of + // the compiler and standard library pairings this project supports, a + // const std::string is not accepted as the left operand of the pipe. + const std::string_view sv{s}; + const std::string_view dv{delimiter}; + + auto range = sv | std::views::split(dv) | std::views::transform([](auto&& p) { return std::string(p.begin(), p.end()); });