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.
// raw code
#include <print>
#include <vector>
#include <array>
#include <algorithm>
int main()
{
std::vector<int> coll{0, 8, 44, 0, 8, 15, 7};
// check whether the range contains a specific value:
auto val = 42;
std::println("{} contains {:<10}: {}", coll, val,
std::ranges::contains(coll, val));
// check whether the range contains a specific sub-sequence:
std::array sub{0, 8, 15};
std::println("{} contains {:<10}: {}",
coll, sub,
std::ranges::contains_subrange(coll, sub));
}