類模板
<ratio>

std::ratio_less

template <class R1, class R2> ratio_less;
比較 ratio 的小於關係
此型別繼承自合適的 integral_constant 型別(true_typefalse_type),用於指示 R1 是否小於 R2
結果型別與以下定義相同:ratio_less定義為
1
2
template <class R1, class R2>
struct ratio_less : integral_constant < bool, R1::num*R2::den < R2::num*R1::den > {};

程式不得導致上述定義中的任何表示式展開為無法表示為intmax_t的值。

模板引數

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_less example
#include <iostream>
#include <ratio>

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

  std::cout << "1/3 < 1/2 ? " << std::boolalpha;
  std::cout << std::ratio_less<one_third,one_half>::value << std::endl;

  return 0;
}

輸出
1/3 < 1/2 ? true


另見