From a02aae0b9fdedf54d8ceacf758fe53a3f081df96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Wed, 21 Jan 2026 22:46:19 +0100 Subject: [PATCH] Add C++23 "contains" to basic_string. --- doc/container.qbk | 4 +++- include/boost/container/string.hpp | 28 ++++++++++++++++++++++++++++ test/string_test.cpp | 17 ++++++++--------- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index 7d0a249..51ac0c1 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1459,7 +1459,9 @@ use [*Boost.Container]? There are several reasons for that: * If available, uses C++17's utilities under the `__cpp_aligned_new` feature. * Uses alternative aligned allocation functions (`posix_memalign`, `aligned_alloc`, `_aligned_malloc`...) otherwise. * Implemented overaligned allocation support for `adaptive_pool`and `node_allocator` -* Updated `basic_string` to the latest standard API: Added missing `string_view` members and updated `operator[]` to be able to return the terminating null. +* Updated `basic_string` to the latest standard API: + * Added missing `string_view` members and updated `operator[]` to be able to return the terminating null. + * Added C++23 `contains` overloads * Fixed bugs/issues: * [@https://github.com/boostorg/container/issues/323 GitHub #323: ['"flat_tree::try_emplace UB"]]. * [@https://github.com/boostorg/container/issues/328 GitHub #328: ['"boost::container::deque stores a redundant copy of the allocator, increasing size"]]. diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index 313cc63..a8d0e89 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -2953,6 +2953,34 @@ class basic_string int compare(size_type pos1, size_type n1, const CharT* s) const { return this->compare(pos1, n1, s, Traits::length(s)); } + //! Effects: Equivalent to find(sv) != npos + //! + //! Throws: Nothing + //! + //! Returns: true if the string contains the provided substring, false otherwise. + template