From dc3a96a29bb407bae9804d33f39d2b0dfc426016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Wed, 21 Jan 2026 23:40:18 +0100 Subject: [PATCH] Add C++20 "starts_with" overloads --- doc/container.qbk | 2 +- include/boost/container/string.hpp | 32 ++++++++++++++++++++++++++++++ test/string_test.cpp | 29 ++++++++------------------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index 51ac0c1..f1664ee 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1461,7 +1461,7 @@ use [*Boost.Container]? There are several reasons for that: * 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. - * Added C++23 `contains` overloads + * Added C++20 `starts_with` and 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 a8d0e89..fc88a54 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -2981,6 +2981,38 @@ class basic_string bool contains(const CharT* s) const BOOST_NOEXCEPT { return this->find(s) != npos; } + //! Effects: Checks if the string begins with the given prefix + //! + //! Throws: Nothing + //! + //! Returns: true if the string begins with the provided prefix, false otherwise. + template