fix: forgot to include a file

This commit is contained in:
Djairo Hougee 2024-04-23 15:02:21 +02:00
parent 855ac4d654
commit 6288a43da7
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#ifndef TO_VECTOR_H
#define TO_VECTOR_H
#include <ranges>
#include <vector>
template <std::ranges::range R>
auto to_vector(R&& r) {
std::vector<std::ranges::range_value_t<R>> v;
// if we can get a size, reserve that much
if constexpr (requires { std::ranges::size(r); }) {
v.reserve(std::ranges::size(r));
}
// push all the elements
for (auto&& e : r) {
v.push_back(static_cast<decltype(e)&&>(e));
}
return v;
}
#endif