AK: Remove default parameter from StringBuilder's constructor

This separates the StringBuilder constructor into 2 constructors. This
essentially allows forming code of the following pattern:

    StringBuilder foo() { return {}; }

Otherwise, we would get the following compiler error:

    chosen constructor is explicit in copy-initialization

Due to the explicitness of the StringBuilder constructor.

This is required for an upcoming update to ICU 76, where we use our
StringBuilder in templated ICU code.
This commit is contained in:
Timothy Flynn 2025-01-18 10:39:34 -05:00 committed by Tim Flynn
parent e5d521bef8
commit c2741ea85e
Notes: github-actions[bot] 2025-01-18 22:58:05 +00:00
2 changed files with 7 additions and 1 deletions

View file

@ -40,6 +40,11 @@ ErrorOr<StringBuilder> StringBuilder::create(size_t initial_capacity)
return StringBuilder { move(buffer) };
}
StringBuilder::StringBuilder()
: StringBuilder(inline_capacity)
{
}
StringBuilder::StringBuilder(size_t initial_capacity)
: m_buffer(MUST(create_buffer(initial_capacity)))
{

View file

@ -23,7 +23,8 @@ public:
static ErrorOr<StringBuilder> create(size_t initial_capacity = inline_capacity);
explicit StringBuilder(size_t initial_capacity = inline_capacity);
StringBuilder();
explicit StringBuilder(size_t initial_capacity);
~StringBuilder() = default;
ErrorOr<void> try_append(StringView);