How do I use in constexpr contexts std::span in C++?

In C++, the `std::span` type provides a view over a contiguous sequence of elements, which can be particularly useful in constexpr contexts for compile-time evaluations. This document discusses how to effectively use `std::span` in such contexts.
constexpr, std::span, C++, compile-time, contiguous sequence, modern C++

#include <span>
#include <array>
#include <iostream>

constexpr std::span<const int> createSpan(const int* arr, std::size_t size) {
    return std::span<const int>(arr, size);
}

constexpr int calculateSum(std::span<const int> sp) {
    int sum = 0;
    for (const auto& value : sp) {
        sum += value;
    }
    return sum;
}

int main() {
    constexpr std::array<int, 5> arr = {1, 2, 3, 4, 5};
    constexpr auto sp = createSpan(arr.data(), arr.size());
    constexpr int total = calculateSum(sp);
    
    std::cout << "Sum: " << total << std::endl; // Outputs: Sum: 15
    return 0;
}
    

constexpr std::span C++ compile-time contiguous sequence modern C++