News for hackers. Stuff that matters.
Re:Go generics are not bad by dataangel on Saturday July 09, 2022 @01:24AM (#32032024)
Writing a generic function to sum an array of any numbers type is trivial in C++. There's no 4 day research period, even if you're new to templates.

    template<class T>
    T sum(T* x, size_t size)
    {
        T acc = 0;
        for(size_t i = 0; i < size; ++i)
            acc += x[i];
        return acc;
    }
Re:Go generics are not bad by e12e on Saturday July 09, 2022 @02:16AM (#32032370)
Isn't acc and the xs same width here? So you risk overflow?
Re:Go generics are not bad by xigoi on Saturday July 09, 2022 @05:53AM (#32033474)
Yes, obviously calculating the sum of fixed-width integers may result in overflow.