An interesting question popped up on stackoverflow about palindrome detection in c++. A palindrome is a word whose characters can be reversed, and no change is detectable, e.g. “racecar”. My initial thought was to make a copy and use the std::reverse algorithm …
1 2 3 4 |
|
However, this copy can be avoided using reverse itterators . .
1 2 3 4 5 6 |
|
Seeing as this function only contains a single command, it might be nice to use a lambda as an alternative. You can specify a return type from a lambda with this syntax
1
|
|
So defining the palindrome detector becomes a simple 1-liner.
1 2 3 |
|