Open
Description
I was wondering if there's a facility such as https://en.cppreference.com/w/cpp/regex/regex_replace in CTRE?
So far I was only able to come up with something not great
static constexpr auto pattern = ctll::fixed_string{" "};
std::string str = get_string();
std::string result;
bool first = true;
for (auto match : ctre::split<pattern>(str)) {
if (!first) {
result += "_";
} else {
first = false;
}
result += std::string{match.get<0>()};
}
fmt::print("{}\n", result);
https://godbolt.org/z/9PMzef97v
A better version but that would require C++26 (join_with is C++23, and ranges::to is C++26): https://godbolt.org/z/9vcTWePGe
Metadata
Metadata
Assignees
Labels
No labels