std::ratio_less
來自 cppreference.com
定義於標頭檔案 <ratio> |
||
template< class R1, class R2 > struct ratio_less : std::integral_constant<bool, /* see below */> { }; |
(C++11 起) | |
如果比例 R1
小於比例 R2
,則提供成員常量 value 等於 true。否則,value 為 false。
目錄 |
[編輯] 輔助變數模板
template< class R1, class R2 > constexpr bool ratio_less_v = ratio_less<R1, R2>::value; |
(C++17 起) | |
繼承自 std::integral_constant
成員常量
value [靜態] |
如果 R1::num * R2::den < R2::num * R1::den,或等效的避免溢位的表示式,則為 true,否則為 false (public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
std::integral_constant<bool, value> |
[編輯] 示例
執行此程式碼
#include <iostream> #include <ratio> int main() { using x = std::ratio<69, 90>; using y = std::ratio<70, 90>; if constexpr (std::ratio_less_v<x, y>) std::cout << x::num << '/' << x::den << " < " << y::num << '/' << y::den << '\n'; }
輸出
23/30 < 7/9
[編輯] 另請參見
(C++11) |
在編譯時比較兩個 ratio 物件是否“大於”(類模板) |