ratio - C++11, 13 of n

C++11 provides ratio lib to specify compile-time fractions and to perform compile-time arithmetic with them.
1) The definition

template
class ratio {
public:
    typedef ratio type;
    static constexpr intmax_t num;
    static constexpr intmax_t den;
};

typedef ratio<5,3> FiveThirds;
cout << FiveThirds::num << "/" << FiveThirds::den << endl;
typedef ratio<25,15> AlsoFiveThirds

cout << AlsoFiveThirds::num << "/" << AlsoFiveThirds::den << endl

2) Operations

Note: ratio_equal,ratio<25,15>>::value // yields true

3) Predefined constants


你可能感兴趣的:(C++)