https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111091
Bug ID: 111091
Summary: Split view with double quoted string
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: deco33000 at yandex dot com
Target Milestone: ---
Hi,
I have just been caught by an overlook using range split, but it may happen to
others.
The issue is the Try1 bypasses the delimiter (maybe because of a char
conversion?)
The other versions work fine though..
As usual, to ease your life: https://godbolt.org/z/7nMK46bjq
--------------------------------------------
#include <iostream>
#include <ranges>
#include <string>
#include <string_view>
using namespace std; // for simplicity
int main() {
string a{"Part A / Part B"};
{
cout << "Try 1 : with double quote (wrong behavior? delim is
bypassed)\n";
auto v = ::ranges::views::split(a, "/");
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 1bis : explicitly convert to string: OK\n";
auto v = ::ranges::views::split(a, string("/"));
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 2 : with single quote: OK\n";
auto v = ::ranges::views::split(a, '/');
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 3 : with string delimiter: OK\n";
string delim{"/"};
auto v = ::ranges::views::split(a, delim);
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
{
cout << "Try 4 : with string delimiter: OK\n";
string delim{'/'};
auto v = ::ranges::views::split(a, delim);
for (auto &&word : v) {
cout << string_view(word) << ' ';
}
cout << "\n\n";
}
return 0;
}
Do you think we could make Try1 to work properly ?
Thanks