最終更新日時:
が更新

履歴 編集

function
<typeindex>

std::type_index::operator<=(C++11)

bool operator<=(const type_index& rhs) const noexcept;

概要

左辺が右辺以下かの判定を行う。

戻り値

!rhs.target->before(*target)

※targetは、type_indexのメンバ変数として保持されているtype_infoオブジェクトへのポインタ(説明用)

例外

投げない

例

#include <iostream>
#include <typeindex>
#include <typeinfo>

int main()
{
  std::type_index a = typeid(int);
  std::type_index b = typeid(double);

  std::cout << std::boolalpha;

  // 同じ型を表すtype_index同士は等価なので、<=はtrueになる
  std::cout << (a <= a) << std::endl;

  // 異なる型を表すtype_index間の照合順序は処理系定義であるため、
  // どちらが前になるかは処理系によって異なる
  const std::type_index& lo = (a < b) ? a : b;
  const std::type_index& hi = (a < b) ? b : a;

  std::cout << (lo <= hi) << std::endl;
  std::cout << (hi <= lo) << std::endl;
}

出力例

true
true
false

バージョン

言語

  • C++11

処理系