From 29df33a4e9cd322fff2263215bb06a0992b99c74 Mon Sep 17 00:00:00 2001 From: studiosi Date: Sat, 22 Aug 2026 10:16:53 +0300 Subject: [PATCH] Solved: 41 - Structured Bindings --- modules/11_cpp17/src/structured_bindings.cpp | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/11_cpp17/src/structured_bindings.cpp b/modules/11_cpp17/src/structured_bindings.cpp index 15f3ac7..da747e1 100644 --- a/modules/11_cpp17/src/structured_bindings.cpp +++ b/modules/11_cpp17/src/structured_bindings.cpp @@ -1,20 +1,32 @@ #include "structured_bindings.hpp" +#include + namespace cpp17 { auto minmax_pair(const std::vector& data) -> std::pair { - (void)data; - return {0, 0}; + auto min = std::numeric_limits::max(); + auto max = std::numeric_limits::min(); + for (const auto i : data) { + if (i < min) min = i; + if (i > max) max = i; + } + return {min, max}; } auto split_key_value(const std::string& text) -> std::pair { - (void)text; - return {"", ""}; + auto r = std::views::split(text, '='); + auto it = r.begin(); + auto key = *it | std::ranges::to(); + ++it; + auto value = *it | std::ranges::to(); + return {key, value}; } auto first_pair(const std::map& scores) -> std::tuple { - (void)scores; - return {"", 0, false}; + if (scores.empty()) return {"", 0, false}; + const auto& [name, score] = *scores.begin(); + return {name, score, true}; } } // namespace cpp17