5 Comments

  1. Marcel Wid

    I don’t like the enable_if part being part of the function signature. The converting constructor from an itegral type to Rational should take 1 argument and not 2. So make enable_if a template parameter. Then one problem remains: If we pass for example 1ul (type unsigned long int) to this constructor, we get a narrowing conversion. Using braces (uniform initialization) solves this problem too.

    template <typename T, typename std::enable_if<std::is_integral::value>::type* = nullptr>
    Rational(T n) : numerator_{n}, denominator_{1} {}

    Reply
    1. Arne Mertz

      Thank you for the input, I fixed it.

      Reply
      1. vlad

        In the first code snippet (top of the page),

        typename std::enable_if …..

        should be

        typename std::enable_if<std::is_integral::value>

        Reply
        1. vlad

          Sorry, my prev. comment was somehow mis-parsed. You are missing the template T for std::is_integral in the first code snippet.

          Reply

Leave a Reply

Your email address will not be published. Required fields are marked *