chore(cpp): rework reading collections

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-08-12 23:17:31 +02:00
parent e928da17af
commit 35e432c481
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -131,17 +131,22 @@ decltype(auto) y_combinator(Fun &&fun) {
#pragma endregion /* functional */ #pragma endregion /* functional */
#pragma region input #pragma region input
template <typename T> template <typename Container>
std::vector<T> load_vector(std::size_t size) { void collect(Container &c, std::size_t size) {
std::vector<T> result{}; auto it = std::inserter(c, c.begin());
for (auto i = 0u; i < size; ++i) { for (auto i = 0u; i < size; ++i) {
T x; typename Container::value_type x;
std::cin >> x; std::cin >> x;
result.push_back(std::move(x)); it = std::move(x);
}
} }
return result; template <typename Container>
Container collect(std::size_t size) {
Container c{};
collect(c, size);
return c;
} }
#pragma endregion /* input */ #pragma endregion /* input */