Solved: 41 - Structured Bindings
This commit is contained in:
@@ -1,20 +1,32 @@
|
|||||||
#include "structured_bindings.hpp"
|
#include "structured_bindings.hpp"
|
||||||
|
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
namespace cpp17 {
|
namespace cpp17 {
|
||||||
|
|
||||||
auto minmax_pair(const std::vector<int>& data) -> std::pair<int, int> {
|
auto minmax_pair(const std::vector<int>& data) -> std::pair<int, int> {
|
||||||
(void)data;
|
auto min = std::numeric_limits<int>::max();
|
||||||
return {0, 0};
|
auto max = std::numeric_limits<int>::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<std::string, std::string> {
|
auto split_key_value(const std::string& text) -> std::pair<std::string, std::string> {
|
||||||
(void)text;
|
auto r = std::views::split(text, '=');
|
||||||
return {"", ""};
|
auto it = r.begin();
|
||||||
|
auto key = *it | std::ranges::to<std::string>();
|
||||||
|
++it;
|
||||||
|
auto value = *it | std::ranges::to<std::string>();
|
||||||
|
return {key, value};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto first_pair(const std::map<std::string, int>& scores) -> std::tuple<std::string, int, bool> {
|
auto first_pair(const std::map<std::string, int>& scores) -> std::tuple<std::string, int, bool> {
|
||||||
(void)scores;
|
if (scores.empty()) return {"", 0, false};
|
||||||
return {"", 0, false};
|
const auto& [name, score] = *scores.begin();
|
||||||
|
return {name, score, true};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cpp17
|
} // namespace cpp17
|
||||||
|
|||||||
Reference in New Issue
Block a user