Title
Rational Arithmetic should use template aliases
Status
c++11
Section
[ratio.ratio]
Submitter
Pablo Halpern

Created on 2008-10-07.00:00:00 last changed 162 months ago

Messages

Date: 2011-04-30.23:09:42

Proposed resolution:

  1. In [ratio] p.3 change as indicated:

    // ratio arithmetic
    template <class R1, class R2> structusing ratio_add = see below;
    template <class R1, class R2> structusing ratio_subtract = see below;
    template <class R1, class R2> structusing ratio_multiply = see below;
    template <class R1, class R2> structusing ratio_divide = see below;
    
  2. In [ratio.ratio], change as indicated:

    namespace std {
      template <intmax_t N, intmax_t D = 1>
      class ratio {
      public:
        typedef ratio type;
        static const intmax_t num;
        static const intmax_t den;
      };
    }
    
  3. In [ratio.arithmetic] change as indicated:

    template <class R1, class R2> structusing ratio_add = see below{
      typedef see below type;
    };
    

    1 The nested typedef type ratio_add<R1, R2> shall be a synonym for ratio<T1, T2> where T1 has the value R1::num * R2::den + R2::num * R1::den and T2 has the value R1::den * R2::den.

    template <class R1, class R2> structusing ratio_subtract = see below{
      typedef see below type;
    };
    

    2 The nested typedef type ratio_subtract<R1, R2> shall be a synonym for ratio<T1, T2> where T1 has the value R1::num * R2::den - R2::num * R1::den and T2 has the value R1::den * R2::den.

    template <class R1, class R2> structusing ratio_multiply = see below{
      typedef see below type;
    };
    

    3 The nested typedef type ratio_multiply<R1, R2> shall be a synonym for ratio<T1, T2> where T1 has the value R1::num * R2::num and T2 has the value R1::den * R2::den.

    template <class R1, class R2> structusing ratio_divide = see below{
      typedef see below type;
    };
    

    4 The nested typedef type ratio_divide<R1, R2> shall be a synonym for ratio<T1, T2> where T1 has the value R1::num * R2::den and T2 has the value R1::den * R2::num.

  4. In [time.duration.cons] p.4 change as indicated:

    Requires: treat_as_floating_point<rep>::value shall be true or ratio_divide<Period2, period>::type::den shall be 1.[..]

  5. In [time.duration.cast] p.2 change as indicated:

    Returns: Let CF be ratio_divide<Period, typename ToDuration::period>::type, and [..]

Date: 2010-10-21.18:28:33

[ 2009-10 Santa Cruz: ]

Move to Ready.

Date: 2009-07-21.00:00:00

[ 2009-07-21 Alisdair adds: ]

See 1121 for a potentially incompatible proposal.

Date: 2010-10-21.18:28:33

[ Batavia (2009-05): ]

Bill asks for additional discussion in the issue that spells out more details of the implementation. Howard points us to issue 948 which has at least most of the requested details. Tom is strongly in favor of overflow-checking at compile time. Pete points out that there is no change of functionality implied. We agree with the proposed resolution, but recommend moving the issue to Review to allow time to improve the discussion if needed.

Date: 2009-05-11.00:00:00

[ 2009-05-11 Pablo adds: ]

The addition of type to the ratio template allows the previous style (i.e., in the prototype implementations) to remain valid and permits the use of transitional library implementations for C++03 compilers. I do not feel strongly about its inclusion, however, and leave it up to the reviewers to decide.

Date: 2009-05-11.00:00:00

[ 2009-05-11 Daniel adds: ]

Personally I'm not in favor for the addition of:

typedef ratio type;

For a reader of the standard it's usage or purpose is unclear. I haven't seen similar examples of attempts to satisfy non-feature complete compilers.

Date: 2010-10-21.18:28:33

[ Post Summit: ]

Jens: not a complete proposed resolution: "would need to make similar change"

Consensus: We agree with the direction of the issue.

Recommend Open.

Date: 2008-10-07.00:00:00

The compile-time functions that operate on ratio<N,D> require the cumbersome and error-prone "evaluation" of a type member using a meta-programming style that predates the invention of template aliases. Thus, multiplying three ratios a, b, and c requires the expression:

ratio_multiply<a, ratio_multiply<b, c>::type>::type

The simpler expression:

ratio_multiply<a, ratio_multiply<b, c>>

Could be used by if template aliases were employed in the definitions.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg4382
2010-10-21 18:28:33adminsetmessages: + msg4381
2010-10-21 18:28:33adminsetmessages: + msg4380
2010-10-21 18:28:33adminsetmessages: + msg4379
2010-10-21 18:28:33adminsetmessages: + msg4378
2010-10-21 18:28:33adminsetmessages: + msg4377
2010-10-21 18:28:33adminsetmessages: + msg4376
2008-10-07 00:00:00admincreate