From 3b2e03acb3fdf19e5546c29363fa538f59da22df Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 2 Jul 2026 19:20:39 +0200 Subject: kstd: implement some assign overloads for string --- libs/kstd/kstd/bits/basic_string.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libs/kstd/kstd/bits/basic_string.hpp b/libs/kstd/kstd/bits/basic_string.hpp index c780a083..1675434c 100644 --- a/libs/kstd/kstd/bits/basic_string.hpp +++ b/libs/kstd/kstd/bits/basic_string.hpp @@ -408,6 +408,36 @@ namespace kstd //! Assignment from nullptr is prohibited. constexpr auto operator=(std::nullptr_t) = delete; + //! Assign a new value to this string. + //! + //! @param string The string to use to replace this strings value. + //! @return A reference to this string after assignment. + constexpr auto assign(basic_string const & string) -> basic_string & + { + return *this = string; + } + + //! Assign a new value to this string. + //! + //! @param string The string to use to replace this strings value. + //! @return A reference to this string after assignment. + constexpr auto assign(basic_string && string) noexcept(noexcept(*this = std::move(string))) -> basic_string & + { + return *this = std::move(string); + } + + //! Replace the contents of this string with a given number of copies of a given character. + //! + //! @param count The number of copies. + //! @param character The character to use to fill this string. + //! @return A reference to this string after assignment. + constexpr auto assign(size_type count, CharacterType character) -> basic_string & + { + clear(); + resize(count, character); + return *this; + } + //! Get the allocator used by this string. //! //! @return A copy of the allocator used by this string. -- cgit v1.2.3