Ticket #8262: average_fix.patch

File average_fix.patch, 1.1 KB (added by james.hirschorn@…, 10 years ago)

patch correcting numeric::average

  • functional.hpp

     
    246246
    247247        template<typename Left, typename Right, typename EnableIf>
    248248        struct average_base
    249           : functional::divides<Left, Right>
    250         {};
     249        {
     250            // Define the type of the result
     251            typedef typename functional::divides<Left, Right>::result_type result_type;
    251252
     253            result_type operator()(Left & left, Right & right) const
     254            {
     255                return numeric::divides(numeric::plus(left, right), 2);
     256            }
     257        };
     258
    252259        // partial specialization that promotes the arguments to double for
    253260        // integral division.
    254261        template<typename Left, typename Right>
    255262        struct average_base<Left, Right, typename enable_if<are_integral<Left, Right> >::type>
    256           : functional::divides<double const, double const>
     263          : average_base<double const, double const>
    257264        {};
    258265
    259266        template<typename To, typename From, typename EnableIf>