Manipulările raportului în C ++ | Setul 2 (comparație)

Premisă - Manipulările raportului în C ++ | Setul 1 (aritmetică)
În C ++ Fișierul de antet ne permite să manipulăm raporturi folosind diverse alias de șabloane încorporate. Fișierul antet a fost introdus de la C ++ 11 înainte. În acest articol vom discuta despre compararea manipulărilor raportului în C ++. Se folosesc următoarele funcții:

  • RATIO_EGAL
  • RATIO_NOT_EGAL
  • Ratio_greater
  • Ratio_less
  • Ratio_greater_equal
  • Ratio_less_equal

1. RATIO_EGAL: Acest alias al șablonului verifică dacă raporturi în argumentele sale sunt egale . Returnează true dacă egală altceva returnează fals. Returnează a Membru boolean constant 'valoare'
2. RATIO_NOT_EGAL: Acest alias al șablonului verifică dacă raporturi în argumentele sale sunt Nu este egal . Returnează True, dacă nu este egal, dacă egale returnează false. Returnează a Membru boolean constant 'valoare' .  

CPP
   // C++ code to demonstrate the working of   // ratio_equal and ratio_not_equal   #include          #include         // for ratio manipulation   using     namespace     std  ;   // Driver Code   int     main  ()   {      // Declaring ratios      typedef     ratio   <  10       100  >     ratio1  ;      typedef     ratio   <  1       10  >     ratio2  ;      // Checking if ratios are equal using ratio_equal      ratio_equal   <  ratio1       ratio2  >::  value      ?     cout      < <     'Ratios are equal'      :     cout      < <     'Ratios are not equal'  ;      cout      < <     endl  ;      // Checking if ratios are not equal using      // ratio_not_equal      ratio_not_equal   <  ratio1       ratio2  >::  value      ?     cout      < <     'Ratios are not equal'      :     cout      < <     'Ratios are equal'  ;      return     0  ;   }   

Ieșire
Ratios are equal Ratios are equal 

3. Ratio_greater: Acest alias temporar verifică dacă raportul1 este mai mare decât raportul2 . Ea Returnează un membru boolean constant 'valoare' ceea ce returnează adevărat dacă raportul1 este mai mare decât raportul altcineva returnează fals.
4. Ratio_less: Acest alias temporar verifică dacă raportul1 este mai mic decât raportul2 . Ea Returnează un membru boolean constant 'valoare' ceea ce returnează adevărat dacă raportul1 este mai mic decât Ratio2 altceva returnează fals. 

CPP
   // C++ code to demonstrate the working of   // ratio_greater and ratio_less   #include          #include         // for ratio manipulation   using     namespace     std  ;   // Driver Code   int     main  ()   {      // Declaring ratios      typedef     ratio   <  10       100  >     ratio1  ;      typedef     ratio   <  11       100  >     ratio2  ;      // Checking if ratio1 is greater than ratio2      // using ratio_greater      ratio_greater   <  ratio1       ratio2  >::  value      ?     cout      < <     'ratio1 is greater than ratio2'      :     cout      < <     'ratio1 is not greater than ratio2'  ;      cout      < <     endl  ;      // Checking if ratio1 is less than ratio2      // using ratio_less      ratio_less   <  ratio1       ratio2  >::  value      ?     cout      < <     'ratio1 is less than ratio2'      :     cout      < <     'ratio1 is not less than ratio2'  ;      cout      < <     endl  ;      return     0  ;   }   

Ieșire
ratio1 is not greater than ratio2 ratio1 is less than ratio2 

5. Ratio_greater_equal: Acest alias temporar verifică dacă raportul1 este mai mare sau egal decât raportul2 . Ea Returnează un membru boolean constant 'valoare' ceea ce returnează adevărat dacă raportul1 este mai mare sau egal decât raportul altcineva returnează fals.
6. Ratio_less_equal: Acest alias temporar verifică dacă raportul1 este mai mic sau egal decât raportul2 . Ea Returnează un membru boolean constant 'valoare' ceea ce returnează adevărat dacă raportul1 este mai mic sau egal decât raportul altcineva returnează fals. 

CPP
   // C++ code to demonstrate the working of   // ratio_greater_equal and ratio_less_equal   #include          #include         // for ratio manipulation   using     namespace     std  ;   // Driver Code   int     main  ()   {      // Declaring ratios      typedef     ratio   <  10       100  >     ratio1  ;      typedef     ratio   <  1       10  >     ratio2  ;      // Checking if ratio1 is greater or equal than ratio2      // using ratio_greater_equal      ratio_greater_equal   <  ratio1       ratio2  >::  value      ?     cout      < <     'ratio1 is greater or equal than ratio2'      :     cout      < <     'ratio1 is not greater or equal than '      'ratio2'  ;      cout      < <     endl  ;      // Checking if ratio1 is less or equal than ratio2      // using ratio_less_equal      ratio_less_equal   <  ratio1       ratio2  >::  value      ?     cout      < <     'ratio1 is less or equal than ratio2'      :     cout      < <     'ratio1 is not less or equal than ratio2'  ;      cout      < <     endl  ;      return     0  ;   }   

Ieșire
ratio1 is greater or equal than ratio2 ratio1 is less or equal than ratio2