std::ratio_greater
來自 cppreference.com
定義於標頭檔案 <ratio> |
||
template< class R1, class R2 > struct ratio_greater : std::integral_constant<bool, /* see below */> { }; |
(C++11 起) | |
如果比例 R1
大於比例 R2
,則提供成員常量 value 等於 true。否則,value 為 false。
目錄 |
[編輯] 輔助變數模板
template< class R1, class R2 > constexpr bool ratio_greater_v = ratio_greater<R1, R2>::value; |
(C++17 起) | |
繼承自 std::integral_constant
成員常量
value [靜態] |
true 如果 R1::num * R2::den > R2::num * R1::den,或等效的避免溢位的表示式,否則為 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() { static_assert(std::ratio_greater<std::ratio<3, 4>, std::ratio<1, 2>>::value, "3/4 > 1/2"); if (std::ratio_greater<std::ratio<11, 12>, std::ratio<10, 11>>::value) std::cout << "11/12 > 10/11" "\n"; // Since C++17 static_assert(std::ratio_greater_v<std::ratio<12, 13>, std::ratio<11, 12>>); if constexpr (std::ratio_greater_v<std::ratio<12, 13>, std::ratio<11, 12>>) std::cout << "12/13 > 11/12" "\n"; }
輸出
11/12 > 10/11 12/13 > 11/12
[編輯] 另請參閱
(C++11) |
在編譯時比較兩個 ratio 物件是否“大於或等於”(類模板) |