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
No account linked to committer's email address

View file

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