Re:C++17 creates a practical use of the backward array index...
by im3w1l on Monday April 03, 2023 @09:15PM
(#35433710)
if let is such a nice way to express this
One subtle but noteworthy thing is that the idiom only mentions map by name once, which is nice if you have a very long map name, and prevents copy paste bugs where you only update one of the two mentions.
[ Parent
| on HN ]
Re:C++17 creates a practical use of the backward array index...
by paulddraper on Tuesday April 04, 2023 @12:26AM
(#35435068)
Scala:
for (x <- map.get(foo)) {
bob(x)
}
// or
map.get(foo).foreach(bob)
// or
map.get(foo) match {
case Some(x) => bob(x)
}
Re:C++17 creates a practical use of the backward array index...
by olliej on Tuesday April 04, 2023 @02:59PM
(#35444381)
This pattern exists in C++ as well. The specific issue here is that all these STL APIs are in terms of C++'s iterator model, and can't be replaced with a more modern "optional" style that allows this cleaner coding style :-/