Изменения в новых версиях / C++20

#include <array>
#include <cstddef>
#include <iostream>
#include <span>
#include <vector>

// *** before: ***
// a pointer and a length travelled as two separate arguments, and
// keeping them in step was left to the caller; a vector, an array and
// a plain buffer each needed their own overload
int sumOld(const int* data, std::size_t size) {
    int total = 0;
    for (std::size_t i = 0; i < size; ++i) total += data[i];
    return total;
}

// *** in version C++20: ***
int sum(std::span<const int> data) {
    int total = 0;
    for (int n : data) total += n;     // the length travels with the pointer
    return total;
}

int main() {
    int raw[3] = {123};
    std::vector<int> v{1234};
    std::array<int2> a{56};

    std::cout << sumOld(raw, 3) << "\n";
    std::cout << sum(raw) << " " << sum(v) << " " << sum(a) << "\n";

    std::cout << sum(std::span(v).subspan(12)) << "\n";   // a window, no copy
    std::cout << std::span(v).size() << "\n";
}