// Helper to sanitize a word to lowercase alphanumeric charactersHere, it seems the variable /clean/ is completely superfluous [1].
auto sanitize = [](std::string w) {
auto clean = w | std::views::filter([](char c) { return std::isalnum(c); })
| std::views::transform([](char c) { return std::tolower(c); });
return std::string(clean.begin(), clean.end());
};
// Helper to sanitize a word to lowercase alphanumeric charactersDear Stefan,
auto sanitize = [](std::string w) {
auto clean = w | std::views::filter([](char c) { return std::isalnum(c); })
| std::views::transform([](char c) { return std::tolower(c); });
return std::string(clean.begin(), clean.end());
};
On 8/27/2026 6:47 PM, Stefan Ram wrote:
Has Bjarne thought to include PCRE2 in C++ already?-a Can we use a reg-
ular expression to match ' only if it's inside a word?-a Do we want to account for Unicode single curly quotes too?
C++ has had a regex library since C++11.
auto sanitize = [](std::string w) {Here, it seems the variable /clean/ is completely superfluous [1].
auto clean = w | std::views::filter([](char c) { return std::isalnum(c); })
| std::views::transform([](char c) { return std::tolower(c); });
return std::string(clean.begin(), clean.end());
};
Wouldn't it be much better if std::string() -- the constructor -- could
just use the filter directly? I mean, something like this, instead; un- >tested.
return std::string( w | filter | transform ) ;
auto sanitize = []( ::std::string w ) return ::std::string( w | filter |
transform ) ;
ular expression to match ' only if it's inside a word? Do we want to
account for Unicode single curly quotes too?
"Johann \"Myrkraverk\" Oskarsson" <johann@myrkraverk.invalid> wrote or quoted:
Has Bjarne thought to include PCRE2 in C++ already? Can we use a reg-
ular expression to match ' only if it's inside a word? Do we want to
account for Unicode single curly quotes too?
"::std::regex" was introduced in C++11 (2011), but due to
performance problems, it's scheduled to be deprecated.
Newsgroups: comp.lang.misc,comp.lang.c++
I also have Stroustrup's 4th edition, but I'm not sure it's worth read-
ing to catch up on the latest? What do you think?
I use the word /try/ here because I'm not offhand sure a good word
counting program can be done with strictly a regular expression,
You could read the working draft N5046 as of 2026-05-12, but it's a
bit technical. C++ is moving too fast currently for textbook authors
to keep up, so maybe try websites like cppreference!
Has Bjarne thought to include PCRE2 in C++ already? Can we use a reg-
ular expression to match ' only if it's inside a word? Do we want to
account for Unicode single curly quotes too?
On Fri, 18 Sep 2026 11:05:46 +0800
"Johann \"Myrkraverk\" Oskarsson" <johann@myrkraverk.invalid> gabbled:
Has Bjarne thought to include PCRE2 in C++ already?-a Can we use a reg-
ular expression to match ' only if it's inside a word?-a Do we want to
account for Unicode single curly quotes too?
Instead of ever niche academic circle jerking wrt C++ expansion, it
would be
nice if some more basic stuff was added first that other languages have supported since their inception. Eg, how about a switch() construct that operated on more than just POD types?
std::string mystr = "hello";
:
:
switch(mystr)
{
case "hello": ...
case "world": ...
:
}
etc.
So long as the object had operator==() defined I see no problem with overloading
switch in this way.
The amount of times I've had to write endless if-else's instead of this
I've
lost count of.
boltar@caprica.universe writes: Eg, how about a switch() construct that >>operated on more than just POD types?
Expected in C++29:
inspect (mystr) {
"hello" => { /* ... */ },
"world" => { /* ... */ },
_ => { /* default */ }
};
Why an entirely new construct, just overload switch!
Also I can guarantee than there's a ton of current code that
will already be using the word "inspect" in some way.
On 18 Sep 2026 15:25:17 GMT
ram@zedat.fu-berlin.de (Stefan Ram) gabbled:
boltar@caprica.universe writes: Eg, how about a switch() construct that >>> operated on more than just POD types?
Expected in C++29:
inspect (mystr) {
"hello" => { /* ... */ },
"world" => { /* ... */ },
_ => { /* default */ }
};
Wtf?? Why an entirely new construct, just overload switch! Also I can guarantee than there's a ton of current code that will already be using the word "inspect" in some way.
On 18/09/2026 17:49, boltar@caprica.universe wrote:
On 18 Sep 2026 15:25:17 GMT
ram@zedat.fu-berlin.de (Stefan Ram) gabbled:
boltar@caprica.universe writes:-a-a Eg, how about a switch() construct
that
operated on more than just POD types?
-a Expected in C++29:
inspect (mystr) {
-a-a-a "hello" => { /* ... */ },
-a-a-a "world" => { /* ... */ },
-a-a-a _-a-a-a-a-a-a => { /* default */ }
};
Wtf?? Why an entirely new construct, just overload switch! Also I can
guarantee than there's a ton of current code that will already be
using the
word "inspect" in some way.
"inspect" is /not/ expected in C++29 - Stefan is a bit out of date.-a It
was one of several alternative proposals for a new pattern-matching feature.-a The current candidate is "match", with a syntax like :
-a-a-a-ax match {
-a-a-a-a-a-a-a 0 => std::printf("zero");
-a-a-a-a-a-a-a 1 => std::printf("one");
-a-a-a-a-a-a-a _ => std::printf("something else");
-a-a-a-a}
This works like a normal "switch", but there is no fall-through (so no "break" statements), and it is not weirdly unstructured.
-a-a-a-as match {
-a-a-a-a-a-a-a "zero" => std::printf("zero");
-a-a-a-a-a-a-a "one" => std::printf("one");
-a-a-a-a-a-a-a _ => std::printf("something else");
-a-a-a-a}
It will work with any literal types.-a It can also be used to match
variant types, polymorphic types, etc.
And there are few situations where an existing identifier "match" could
be in conflict with the new keyword.-a (You could cause trouble with a
macro called "match", but that seems unlikely in real code.)
boltar@caprica.universe wrote or quoted:
Why an entirely new construct, just overload switch!
Switch already has fall-through semantic which is not desired
for the new inspect statement. Also parsing both the old and
the new "case" syntax can become difficult.
Also I can guarantee than there's a ton of current code that
will already be using the word "inspect" in some way.
If the compiler sees "inspect (variable) { ... }", it parses
it as a pattern-matching block.
If it sees "int inspect = 5;" or "my_object.inspect()", it treats
it as a completely valid standard identifier.
On 18 Sep 2026 16:05:52 GMT
ram@zedat.fu-berlin.de (Stefan Ram) gabbled:
boltar@caprica.universe wrote or quoted:
Why an entirely new construct, just overload switch!
Switch already has fall-through semantic which is not desired
for the new inspect statement. Also parsing both the old and
Says who?
the new "case" syntax can become difficult.
Rubbish. Other languages manage.
Also I can guarantee than there's a ton of current code that
will already be using the word "inspect" in some way.
If the compiler sees "inspect (variable) { ... }", it parses
it as a pattern-matching block.
If it sees "int inspect = 5;" or "my_object.inspect()", it treats
it as a completely valid standard identifier.
So we treat "inspect" differently to every other keyword in that it can be used as a variable/function/whatever name too? Well that won't be confusing at all!
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 122:20:30 |
| Calls: | 1,194 |
| Files: | 1,352 |
| Messages: | 290,355 |