// Stage 06: read in two passes: ownership first, generic summation later.
#include <algorithm>
#include <concepts>
#include <iostream>
#include <memory>
#include <span>
#include <utility>
#include <vector>
struct ReadingBatch {std::vector<int> readings;};
template<std::integral T>
long long total_of(std::span<const T> readings) {
    long long total=0;
    for(const T value:readings) total+=value;
    return total; // Only the documented small teaching values are supplied; this is not checked arithmetic.
}
int main() {
    auto owner=std::make_unique<ReadingBatch>(ReadingBatch{{3,1,4,1,5}});
    const std::span<const int> borrowed{owner->readings};
    auto snapshot=*owner;snapshot.readings[0]+=10;
    auto next_owner=std::move(owner); // Transfer the pointer, not the pointee.
    if(owner || !next_owner) return 1;
    int threshold=3;
    const auto large=[threshold](int reading){return reading>=threshold;};
    const auto count=std::count_if(borrowed.begin(),borrowed.end(),large);
    const std::vector<short> small_type{3,1,4,1,5};
    const std::vector<unsigned char> bytes{250,10};
    if(total_of<int>(borrowed)!=14 || total_of<int>(snapshot.readings)!=24 ||
       total_of<short>(small_type)!=14 || total_of<unsigned char>(bytes)!=260 || count!=3 ||
       total_of<int>(std::span<const int>{})!=0) return 2;
    std::cout<<"owner_empty="<<(!owner)<<" next=14 snapshot=24 large="<<count<<'\n';
    std::cout<<"generic_int=14 generic_short=14\n";
}
