constexpr bool ends_with(basic_string_view x) const noexcept; // (1)
constexpr bool ends_with(CharT x) const noexcept; // (2)
constexpr bool ends_with(const CharT* x) const; // (3)
概要
指定の文字列で終わるかを判定する。
- (1) :
*this
が参照する文字列範囲の末尾が、x
が参照する文字列範囲と一致するかを判定する - (2) :
*this
が参照する文字列範囲の末尾が、文字x
と一致するかを判定する - (3) :
*this
が参照する文字列範囲の末尾が、文字列x
と一致するかを判定する
戻り値
-
(1) : 以下と等価である
-
(2) : 以下と等価である
return !empty() && Traits::eq(back(), x);
-
(3) : 以下と等価である
return ends_with(basic_string_view(x));
例外
- (1), (2) : 投げない
例
#include <cassert>
#include <string_view>
int main()
{
const std::string_view sv = "aaabbbcccdddeee";
// (1)
{
std::string_view svx = "eee";
assert(sv.ends_with(svx));
}
// (2)
{
assert(sv.ends_with('e'));
}
// (3)
{
assert(sv.ends_with("eee"));
}
}
xxxxxxxxxx
#include <cassert>
#include <string_view>
int main()
{
const std::string_view sv = "aaabbbcccdddeee";
// (1)
{
std::string_view svx = "eee";
assert(sv.ends_with(svx));
}
// (2)
{
assert(sv.ends_with('e'));
}
// (3)
{
assert(sv.ends_with("eee"));
}
}
出力
バージョン
言語
- C++20
処理系
- Clang: 7.0 ✅
- GCC: 9.1 ✅
- Visual C++: ??