New paste Use cases Explore public pastes Text tools Developer API The Paste Library Security Sign in with Google
CPPExample pasteCreated 2026-07-312 viewsNo expiry

C++ average using std::span

Raw New paste
cppRead-only
1
#include <numeric>
#include <span>
#include <stdexcept>

double average(std::span<const double> values) {
    if (values.empty()) {
        throw std::invalid_argument("values must not be empty");
    }
    const double sum = std::accumulate(values.begin(), values.end(), 0.0);
    return sum / static_cast<double>(values.size());
}
Report abuse

Paste details

Visibility
Public
Size
332 bytes
Protection
Standard link access
Retention
No automatic expiry

Share with confidence

Unlisted links are not searchable, but anyone with the URL can open them. Never paste live credentials or personal data.