algo/endswith.cpp

The following code example is taken from the book
C++23 - The Complete Guide by Nicolai M. Josuttis, Leanpub, 2026
The code is licensed under a Creative Commons Attribution 4.0 International License. Creative Commons License

// raw code

#include <print>
#include <vector>
#include <list>
#include <algorithm>

int main()
{
  std::vector<int> coll{0, 8, 15, 47, 11, 8, 0};
  std::list<long> sub{0, 8};

  std::println("{} starts with {}: {}", coll, sub,
                                        std::ranges::starts_with(coll, sub));

  std::println("{} ends with   {}: {}", coll, sub,
                                        std::ranges::ends_with(coll, sub));
}