-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
sstring: add more accessors #1755
Conversation
this change was inspired by https://github.com/scylladb/scylladb/pull/14800/files#diff-7b428ff10eee5bec5a6f74223c8dee8d61085bbaf290538bd3ae6e8c4c606efdR1139 where the author uses if (!fn_name.find("castas")) {
// something we should do when fn_name starts with "castas"
} IMHO, this is not quite readable. |
0e4c7fb
to
f53aaac
Compare
to be compliant with the C++20 standard, which requires that a string should have following find() overloads: template<class T> constexpr size_type find(const T& t, size_type pos = 0) const noexcept // where T should be convertible to basic_string_view constexpr size_type find(const charT* s, size_type pos, size_type n) const; constexpr size_type find(const charT* s, size_type pos = 0) const; so let's provide these overloads, so that sstring can be used in lieu of std::string, when appropriate. see also https://eel.is/c++draft/basic.string#string.ops Signed-off-by: Kefu Chai <[email protected]>
as required by the C++20 standard, std::string should provide constexpr const charT& front() const; constexpr charT& front(); so let's add them to sstring. so that sstring can be used in lieu of std::string, when appropriate. see also https://eel.is/c++draft/basic.string#string.access Signed-off-by: Kefu Chai <[email protected]>
as required by the C++20 standard, std::string should provide constexpr bool starts_with(basic_string_view<charT, traits> x) const noexcept; constexpr bool starts_with(charT x) const noexcept; constexpr bool starts_with(const charT* x) const; so let's add them to sstring. . so that sstring can be used in lieu of std::string, when appropriate. see also https://eel.is/c++draft/string.starts.with Signed-off-by: Kefu Chai <[email protected]>
as required by the C++20 standard, std::string should provide constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept; constexpr bool ends_with(charT x) const noexcept; constexpr bool ends_with(const charT* x) const; so let's add them to sstring. . so that sstring can be used in lieu of std::string, when appropriate. see also https://eel.is/c++draft/string.ends.with Signed-off-by: Kefu Chai <[email protected]>
as required by the C++20 standard, std::string should provide constexpr bool contains(basic_string_view<charT, traits> x) const noexcept; constexpr bool contains(charT x) const noexcept; constexpr bool contains(const charT* x) const; so let's add them to sstring. . so that sstring can be used in lieu of std::string, when appropriate. see also https://eel.is/c++draft/string.contains Signed-off-by: Kefu Chai <[email protected]>
f53aaac
to
3ea436e
Compare
} | ||
|
||
template<class StringViewLike, | ||
std::enable_if_t<std::is_convertible_v<StringViewLike, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity check: usage of SEASTAR_CONCEPT is now not mandatory, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, disregard, it's not a concept 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think these helpers are also handy to C++17 users, so chose to avoid using C++20.
I agree that seastar::sstring should be more compatible with std::string, but I don't agree with your wish to use seastar::sstring in lieu of std::string - I think it should be the other way around, Seastar applications should avoid seastar::sstring as much as possible - see #634 |
sorry for the misunderstanding. i think, i, well, again, sent the wrong message to the reviewer and greater community. i am not a big fan of but @xemul mentioned at seastar/include/seastar/core/sstring.hh Lines 56 to 59 in ba1e39d
BTW, the initiative to remove the formatters for standard library containers in Seastar and ScyllaDB is of the same spirit, despite it is difficult in the sense of the amount of work. |
I think that sstring should mirror std::string as far as possible. It would have been better to use std::string, but we measured a significant performance degradation with it. |
in this series, more accessors are added to
seastar::sstring
. the goal is to make sstring more standard compliant, so that it can be used in lieu ofstd::string
when appropriate.