Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/ratio/ratio equal"

From cppreference.com
< cpp‎ | numeric‎ | ratio
(+_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}}
{{dcl begin}}
+
{{|ratio|1=
{{dcl header | ratio}}
+
{{dcl | 1=
+
 
template< class R1, class R2 >
 
template< class R1, class R2 >
struct ratio_equal : std::integral_constant;
+
struct ratio_equal : std::integral_constant;
 
}}
 
}}
{{dcl end}}
 
  
If the ratios R1 and R2 are equal, provides the member constant {{tt|value}} equal {{c|true}}. Otherwise, {{tt|value}} is {{c|false}}.
+
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=
+
|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=
| code=
+
 
#include <iostream>
 
#include <iostream>
 
#include <ratio>
 
#include <ratio>
 
+
 
int main()
 
int main()
 
{
 
{
     if(std::ratio_equal<std::ratio<2,3>, std::ratio<4,6>>::value) {
+
     std::<std::ratio<2,3>,
        std::cout << "2/3 == 4/6\n";
+
std::ratio<6>>
    } else {
+
)
        std::cout << "2/3 != 4/6\n";
+
std::cout << "2/3 ==" : << " /\n";
    }
+
 
}
 
}
| output=
+
|output=
2/3 == 4/6
+
2/3 == 6
 
}}
 
}}
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/experimental/type_traits_v | ratio_equal}}
+
{{dsc inc|cpp//}}
 
{{dsc end}}
 
{{dsc end}}
  
[[de:cpp/numeric/ratio/ratio equal]]
+
deesfritjaptruzh
[[es:cpp/numeric/ratio/ratio equal]]
+
[[fr:cpp/numeric/ratio/ratio equal]]
+
[[it:cpp/numeric/ratio/ratio equal]]
+
[[ja:cpp/numeric/ratio/ratio equal]]
+
[[pt:cpp/numeric/ratio/ratio equal]]
+
[[ru:cpp/numeric/ratio/ratio equal]]
+
[[zh:cpp/numeric/ratio/ratio equal]]
+

Latest revision as of 15:46, 24 September 2024

 
 
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11)(deprecated in C++26)
(C++11)(until C++20*)
(C++11)(deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)(deprecated in C++23)
(C++11)(deprecated in C++23)