Skip to content

Latest commit

 

History

History
68 lines (53 loc) · 1.35 KB

File metadata and controls

68 lines (53 loc) · 1.35 KB

operator==

  • string_view[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp17[meta cpp]
namespace std {
  template <class CharT, class Traits>
  constexpr bool operator==(basic_string_view<CharT, Traits> x,
                            basic_string_view<CharT, Traits> y) noexcept; // (1) C++17
}

概要

basic_string_viewオブジェクトの等値比較を行う。

戻り値

return x.compare(y) == 0;
  • compare[link compare.md]

備考

  • この演算子により、以下の演算子が使用可能になる (C++20):
    • operator!=

#include <iostream>
#include <string_view>

int main()
{
  std::string_view a = "aaa";
  std::string_view b {"aaaBB", 3}; // 先頭3文字を参照

  if (a == b) {
    std::cout << "equal" << std::endl;
  }
  else {
    std::cout << "not equal" << std::endl;
  }
}

出力

equal

バージョン

言語

  • C++17

処理系

参照