Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 1.36 KB

op_less.md

File metadata and controls

58 lines (44 loc) · 1.36 KB

operator<

  • utility[meta header]
  • std[meta namespace]
  • function template[meta id-type]
namespace std {
  // operator<=>により、以下の演算子が使用可能になる (C++20)
  template <class T1, class T2>
  bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y);           // (1) C++03

  template <class T1, class T2>
  constexpr bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y); // (1) C++14
}

概要

2つのpairについて、左辺が右辺より小さいかの判定を行う

戻り値

return x.first < y.first || (!(y.first < x.first) && x.second < y.second);

#include <iostream>
#include <utility>
#include <string>

int main()
{
  std::pair<int, std::string> p1(1, "aaa");
  std::pair<int, std::string> p2(2, "bbb");

  std::cout << std::boolalpha;
  std::cout << (p1 < p2) << std::endl;
  std::cout << (p2 < p1) << std::endl;
}

出力

true
false

関連項目

参照