From 639337e0794f7527212554ba7eff71baa97aa836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 2 Jan 2026 18:46:33 +0100 Subject: [PATCH] Add missing string_view-like overloads for assign, insert and append. --- include/boost/container/string.hpp | 69 +- test/string_test.cpp | 1900 ++++++++++++++++++++++++++++ 2 files changed, 1962 insertions(+), 7 deletions(-) diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index fb4dd9e..fce660d 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -1437,6 +1437,23 @@ class basic_string s.begin() + pos + dtl::min_value(n, s.size() - pos)); } + //! Requires: pos <= sv.size() + //! + //! Effects: Determines the effective length rlen of the string to append + //! as the smaller of n and sv.size() - pos and calls append(sv.data() + pos, rlen). + //! + //! Throws: If memory allocation throws and out_of_range if pos > sv.size() + //! + //! Returns: *this + template class BasicStringView> + basic_string& append(BasicStringView sv, size_type pos, size_type n = npos) + { + if (pos > sv.size()) + throw_out_of_range("basic_string::append out of range position"); + return this->append(sv.begin() + pos, + sv.begin() + pos + dtl::min_value(n, sv.size() - pos)); + } + //! Requires: s points to an array of at least n elements of CharT. //! //! Effects: The function replaces the string controlled by *this with @@ -1499,12 +1516,18 @@ class basic_string } } - //! Effects: Equivalent to assign(str, 0, npos). + //! Effects: return *this = s; //! //! Returns: *this basic_string& assign(const basic_string& s) { return this->operator=(s); } + //! Effects: return *this = move(s); + //! + //! Returns: *this + basic_string& assign(BOOST_RV_REF(basic_string) s) BOOST_NOEXCEPT_OR_NOTHROW + { return this->operator=(boost::move(s)); } + //! Effects: Equivalent to return assign(sv.data(), sv.size()). //! //! Returns: *this @@ -1512,15 +1535,22 @@ class basic_string basic_string& assign(BasicStringView sv) { return this->operator=(sv); } - //! Effects: The function replaces the string controlled by *this - //! with a string of length str.size() whose elements are a copy of the string - //! controlled by str. Leaves str in a valid but unspecified state. + //! Requires: pos <= sv.size() //! - //! Throws: Nothing + //! Effects: Determines the effective length rlen of the string to assign as + //! the smaller of n and sv.size() - pos and calls assign(sv.data() + pos rlen). + //! + //! Throws: If memory allocation throws or out_of_range if pos > sv.size(). //! //! Returns: *this - basic_string& assign(BOOST_RV_REF(basic_string) ms) BOOST_NOEXCEPT_OR_NOTHROW - { return this->swap_data(ms), *this; } + template