類模板
<ratio>

std::ratio_equal

template <class R1, class R2> ratio_equal;
比較 ratio
該型別繼承自相應的 integral_constant 型別(true_typefalse_type),用於指示 R1 是否與 R2 相等。
結果型別與以下定義相同:ratio_equal定義為
1
2
template <class R1, class R2>
struct ratio_equal : integral_constant<bool, R1::num==R2::num && R1::den==R2::den> {};

模板引數

R1,R2
要比較的 ratio 型別。

成員常量

繼承自 integral_constant
成員常量定義
truefalse

成員型別

繼承自 integral_constant
成員型別定義
value_typebool
型別true_type 或 false_type

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// ratio_equal example
#include <iostream>
#include <ratio>

int main ()
{
  typedef std::ratio<1,2> one_half;
  typedef std::ratio<2,4> two_fourths;

  std::cout << "1/2 == 2/4 ? " << std::boolalpha;
  std::cout << std::ratio_equal<one_half,two_fourths>::value << std::endl;

  return 0;
}

輸出
1/2 == 2/4 ? true


另見