diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-12-18 15:34:43 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-12-18 15:34:43 +0000 |
commit | 49cefcf3f084dabc327914269e5787bac8b20f46 (patch) | |
tree | 406e57c2a1a44b52f46558830652c1be3689479e | |
parent | 34a9bcaf8b71771f93fe1f09e0c060767bcb7601 (diff) | |
download | gcc-49cefcf3f084dabc327914269e5787bac8b20f46.zip gcc-49cefcf3f084dabc327914269e5787bac8b20f46.tar.gz gcc-49cefcf3f084dabc327914269e5787bac8b20f46.tar.bz2 |
LWG 3040: define starts_with/ends_with as proposed
* include/std/string_view [__cplusplus > 201703L]
(basic_string_view::starts_with(basic_string_view)): Implement
proposed resolution of LWG 3040 to avoid redundant length check.
(basic_string_view::starts_with(_CharT)): Implement proposed
resolution of LWG 3040 to check at most one character.
(basic_string_view::ends_with(_CharT)): Likewise.
From-SVN: r267234
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/std/string_view | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d9dc973..e25b9ce 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2018-12-18 Jonathan Wakely <jwakely@redhat.com> + + * include/std/string_view [__cplusplus > 201703L] + (basic_string_view::starts_with(basic_string_view)): Implement + proposed resolution of LWG 3040 to avoid redundant length check. + (basic_string_view::starts_with(_CharT)): Implement proposed + resolution of LWG 3040 to check at most one character. + (basic_string_view::ends_with(_CharT)): Likewise. + 2018-12-17 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/71044 diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 28d3fa4..ac84b24 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -389,14 +389,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L constexpr bool starts_with(basic_string_view __x) const noexcept - { - return this->size() >= __x.size() - && this->compare(0, __x.size(), __x) == 0; - } + { return this->substr(0, __x.size()) == __x; } constexpr bool starts_with(_CharT __x) const noexcept - { return this->starts_with(basic_string_view(&__x, 1)); } + { return !this->empty() && traits_type::eq(this->front(), __x); } constexpr bool starts_with(const _CharT* __x) const noexcept @@ -411,7 +408,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr bool ends_with(_CharT __x) const noexcept - { return this->ends_with(basic_string_view(&__x, 1)); } + { return !this->empty() && traits_type::eq(this->back(), __x); } constexpr bool ends_with(const _CharT* __x) const noexcept |