最終更新日時(UTC):
が更新

履歴 編集

function
<string>

std::basic_string::ends_with(C++20)

constexpr bool
  ends_with(std::basic_string_view<charT, traits> x) const noexcept; // (1) C++20
constexpr bool
  ends_with(charT x) const noexcept;                                 // (2) C++20
constexpr bool
  ends_with(const charT* x) const;                                   // (3) C++20

概要

指定の文字列で終わるかを判定する。

  • (1) : *thisが保持する文字列の末尾が、xが参照する文字列範囲と一致するかを判定する
  • (2) : *thisが保持する文字列の末尾が、文字xと一致するかを判定する
  • (3) : *thisが保持する文字列の末尾が、文字列xと一致するかを判定する

戻り値

以下と等価である:

return std::basic_string_view<CharT, Traits>(data(), size()).ends_with(x);

例外

  • (1), (2) : 投げない

#include <cassert>
#include <string>

int main()
{
  const std::string s = "aaabbbcccdddeee";

  // (1)
  {
    std::string_view sv = "eee"; 
    assert(s.ends_with(sv));
  }

  // (2)
  {
    assert(s.ends_with('e'));
  }

  // (3)
  {
    assert(s.ends_with("eee"));
  }
}

出力

バージョン

言語

  • C++20

処理系

参照