C++ Logo


Advanced search

[std-proposals] Draft Proposal of std::contains Utilities to the C++ Standard Library

From: Robert Sitton <robert.sitton_at_[hidden]>
Date: Thu, 29 Feb 2024 23:45:56 -0600
Hello again! I am here to propose the addition of three new utility
functions to the C++ Standard Library: std::contains, std::contains_any,
and std::contains_all. These functions are intended to improve direct and
efficient queries on containers and ranges, filling a gap in the current
C++ standard that affects both the readability and maintainability of code.

Here's a quick outline of the proposed utilities:

   - std::contains: checking for a single value within a range or container.
   - std::contains_any: Determines if any of a set of specified values
   exist within a range or container.
   - std::contains_all: ensures all specified values are present within a
   range or container.

These utilities utilize concepts for compile-time type checks to ensure
compatibility and usability, and they are defined for all STL containers,
strings, and ranges. Their implementation guarantees efficiency by using
std::ranges::find, std::ranges::any_of, and std::ranges::all_of.

The addition of std::contains and its related functions could be a major
advancement in the way containers are manipulated in C++. These tools are
highly beneficial for developers, providing them with the ability to write
clearer, more efficient, and robust code. They also improve the readability
of the code and reduce the amount of boilerplate required while focusing on
expressiveness and intent. Additionally, these functions simplify common
container operations, bringing C++ more in line with functionality found in
other major programming languages.

I have attached a detailed proposal document to this email. This document
includes a comprehensive rationale, technical specifications,
implementation examples, and anticipated impact. I believe that these
additions will be highly beneficial for the C++ community. I am eagerly
looking forward to receiving your feedback and suggestions for further



This communication contains confidential information and may be
privileged. If you are not the intended recipient or believe that you have
received this communication in error, please reply to the sender indicating
that fact and delete the copy you received. You should also not print,
copy, re-transmit, disseminate, or otherwise use the information unless
expressly indicated in this communication.

Received on 2024-03-01 05:46:37