Modernes C++ programmieren

Okt 23, 2024

lst-0827-godb.cpp

//#(compile) c++; compiler:g132; options:-O3 -std=c++23; libs:-
// https://godbolt.org/z/WqvM6KEEM 
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
using std::string_view; using namespace std::literals; using std::cout;
auto istPalindrom(string_view sv) {
  return std::ranges::equal(sv.begin(), sv.end(), sv.rbegin(), sv.rend()); };
int main() {
  for(auto s : {"regallager"sv, "rentner"sv, "blutwurst"sv }) {
    cout << s << " ist " << (istPalindrom(s)?"ein":"kein") << " Palindrom\n";
  }
}