From 1f0f5bbf36418a340bd75b8bb48d30c5624a3f4c Mon Sep 17 00:00:00 2001 From: Yuma Endo Date: Tue, 11 Aug 2026 20:17:21 +0900 Subject: [PATCH 1/2] fix: restore the string parameters of split split took its two arguments as std::string_view. The change was made to express that the function does not own them, and it also happened to work around a build failure on one of the supported compiler and standard library pairings, where the left operand of the views pipe was rejected as a const std::string. The parameter change turned out to cost far more than expected. Nine conversion operators to std::string are declared across the library -- covering seven top-level types, among them path -- and none of them declares a conversion to std::string_view. Passing any of them to split therefore needs two user-defined conversions, which the language does not perform, so the library could no longer pass its own types to its own function. Splitting a PATH on ":" is one of the most typical uses of split, and it stopped compiling. The build failure came from the left operand of the pipe, not from the parameter type. Converting inside the function fixes it while leaving the public signature alone, so restore const std::string& and take a view of each argument in the body. The nine split test cases pass unchanged, and the pairing that failed now builds and runs the suite. The two conversions are not obvious to a reader who has not seen the failure, so a comment records why the pipe is not fed the strings directly. Expressing non-ownership in the parameter type remains the more accurate choice, and the wider question of applying it across the rest of the API is still open. Doing it for split alone is what breaks callers, because the surrounding types are built around std::string; done together, the types and the signatures can be designed to agree. --- docs/sphinx/source/changelog.rst | 4 ---- include/dross/type.h | 2 +- src/type.cpp | 10 ++++++++-- 3 files changed, 9 insertions(+), 7 deletions(-) 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..df54447 100644 --- a/include/dross/type.h +++ b/include/dross/type.h @@ -93,7 +93,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..d27004b 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -5,11 +5,17 @@ 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()); }); From e5224b11cca261d375a315c93945737a8177e714 Mon Sep 17 00:00:00 2001 From: Yuma Endo Date: Tue, 11 Aug 2026 20:31:38 +0900 Subject: [PATCH 2/2] refactor: move the string_view include to the file that uses it The public header gained when split declared its parameters that way. After restoring const std::string&, nothing in the header names std::string_view -- the only mention left was the include itself -- while src/type.cpp uses it directly and relied on the header to supply it. Move the include to the translation unit that uses the type. stays in the header, since the declarations do name std::string. --- include/dross/type.h | 1 - src/type.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dross/type.h b/include/dross/type.h index df54447..47ae1af 100644 --- a/include/dross/type.h +++ b/include/dross/type.h @@ -67,7 +67,6 @@ #include #include -#include #include /** diff --git a/src/type.cpp b/src/type.cpp index d27004b..b508cb4 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace dross {