#include <algorithm>
#include <type_traits>

namespace fixed {
    namespace std {
        template <typename InputT, typename T>
            auto accumulate (InputT from, InputT to, T init) ->
              typename ::std::enable_if <::std::is_same<decltype(init+*from),decltype(init+*from+*from)>::value,
                                       decltype(init+*from)>::type
              {
                  return ::std::accumulate(from, to, decltype(init+*from)(init));
              }

        template <typename InputT, typename T, typename Op>
            auto accumulate (InputT from, InputT to, T init, Op op) ->
              typename ::std::enable_if <::std::is_same<decltype(op(init,*from)),decltype(op(op(init,*from),*from))>::value,
                                       decltype(op(init,*from))>::type
              {
                  return ::std::accumulate(from, to, decltype(op(init,*from))(init));
              }

    }
}

#include <iterator>
#include <iostream>
int main ()
{
    int foo[] {1,2,3};
    std::cout << fixed::std::accumulate (std::begin(foo), std::end(foo), 0.5) << std::endl;
    double bar[] {1.1,2.2,3.3};
    std::cout << fixed::std::accumulate (std::begin(bar), std::end(bar), 0) << std::endl;
}