Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic_sstring should havepush_back() #2104

Open
tchaikov opened this issue Feb 15, 2024 · 3 comments · May be fixed by #2106
Open

basic_sstring should havepush_back() #2104

tchaikov opened this issue Feb 15, 2024 · 3 comments · May be fixed by #2106
Assignees

Comments

@tchaikov
Copy link
Contributor

we need to implement constexpr void push_back(char_type ch); for basic_sstring<..>.

tchaikov added a commit to tchaikov/seastar that referenced this issue Feb 17, 2024
to be more compatible with basic_string<>
this is also what we expect from a sequence-alike STL containers.

Fixes scylladb#2104
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
@tchaikov tchaikov linked a pull request Feb 17, 2024 that will close this issue
@tchaikov tchaikov self-assigned this Feb 17, 2024
tchaikov added a commit to tchaikov/seastar that referenced this issue Feb 17, 2024
to be more compatible with basic_string<>
this is also what we expect from a sequence-alike STL containers.

Fixes scylladb#2104
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
@tchaikov
Copy link
Contributor Author

i found this when trying to use something like

sstring s;
fmt::format_to(std::back_inserter(s), "{}", 1);

@avikivity
Copy link
Member

This is a bad use case, since it will have quadratic behavior.

Maybe it's a bad idea to implement push_back as it encourages bad performance.

@nyh
Copy link
Contributor

nyh commented Feb 20, 2024

This is a bad use case, since it will have quadratic behavior.

It shouldn't - according to https://en.cppreference.com/w/cpp/string/basic_string/push_back, the push_back() function has "Amortized constant" complexity, which means that pushing N characters has O(N) complexity, not O(N^2).

Maybe it's a bad idea to implement push_back as it encourages bad performance.

I realize it's harder to do the longer we wait, but I really think we should think about drop sstring and use std::string (i.e., issue #634). I don't say we should do it today, but it's something we should start considering (and should have considered many years ago).
C++23 added even more features to std::string which seastar::sstring doesn't implement, and eventually we'll need :-(

tchaikov added a commit to tchaikov/seastar that referenced this issue Apr 3, 2024
to be more compatible with basic_string<>
this is also what we expect from a sequence-alike STL containers.

Fixes scylladb#2104
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants