Difference between revisions of "cpp/numeric/ratio/ratio equal"
From cppreference.com
(+_v) |
m (-`inline`: CWG2387; fmt.) |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/title | ratio_equal}} | + | {{cpp/title|ratio_equal}} |
{{cpp/numeric/ratio/navbar}} | {{cpp/numeric/ratio/navbar}} | ||
− | {{ | + | {{|ratio|1= |
− | + | ||
− | + | ||
template< class R1, class R2 > | template< class R1, class R2 > | ||
− | struct ratio_equal : std::integral_constant; | + | struct ratio_equal : std::integral_constant; |
}} | }} | ||
− | |||
− | If the ratios R1 and R2 are equal, provides the member constant {{ | + | If the ratios R1and R2are equal, provides the member constant {{|value}} equal {{c|true}}. Otherwise, {{|value}} is {{c|false}}. |
− | === Helper variable template === | + | ===Helper variable template=== |
− | {{ddcl | since=c++17 | 1= | + | {{ddcl|since=c++17|1= |
template< class R1, class R2 > | template< class R1, class R2 > | ||
constexpr bool ratio_equal_v = ratio_equal<R1, R2>::value; | constexpr bool ratio_equal_v = ratio_equal<R1, R2>::value; | ||
}} | }} | ||
− | {{cpp/types/integral_constant/inherit | {{c|1=R1::num == R2::num && R1::den == R2::den}} }} | + | {{cpp/types/integral_constant/inherit|{{c|1=R1::num == R2::num && R1::den == R2::den}}}} |
===Possible implementation=== | ===Possible implementation=== | ||
{{eq fun | {{eq fun | ||
− | + | |1= | |
template< class R1, class R2 > | template< class R1, class R2 > | ||
struct ratio_equal : public std::integral_constant < | struct ratio_equal : public std::integral_constant < | ||
Line 31: | Line 28: | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | ||
#include <iostream> | #include <iostream> | ||
#include <ratio> | #include <ratio> | ||
− | + | ||
int main() | int main() | ||
{ | { | ||
− | + | std::<std::ratio<2,3>, | |
− | + | std::ratio<6>> | |
− | + | ) | |
− | + | std::cout << "2/3 ==" : << " /\n"; | |
− | + | ||
} | } | ||
− | + | |output= | |
− | 2/3 == | + | 2/3 == 6 |
}} | }} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/ | + | {{dsc inc|cpp//}} |
{{dsc end}} | {{dsc end}} | ||
− | + | deesfritjaptruzh | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |