#include #include #include #include #include template auto sum_and_max(It begin, It end) { using value_type = typename It::value_type; value_type sum {}; value_type biggest{*begin}; for (It current { begin }; current != end; ++current) { sum += *current; if (*current < biggest) { biggest = *current; } } return std::make_pair(sum, biggest); } template void print_pair(std::pair const& p) { std::cout << "The sum is: " << p.first << std::endl << "The biggest(>) element is: " << p.second << std::endl; } int main() { std::cout << "==== Testfall #1 ====" << std::endl; // Enkelt testfall std::vector v1 { 1, 2, 4, 3}; auto v1_pair { sum_and_max(v1.begin(), v1.end()) }; print_pair(v1_pair); std::cout << "==== Testfall #2 ====" << std::endl; // Testa std::list (en annan behållare än std::vector) std::list names { "PONTUS ", "CHRISTOFFER ", "ERIC ", "MALTE ", "NILS ", "EDVIN" }; auto names_pair { sum_and_max(names.begin(), names.end()) }; print_pair(names_pair); }