diff --git a/linear-interpolation/src/to_vector.h b/linear-interpolation/src/to_vector.h new file mode 100644 index 0000000..989085b --- /dev/null +++ b/linear-interpolation/src/to_vector.h @@ -0,0 +1,24 @@ +#ifndef TO_VECTOR_H +#define TO_VECTOR_H + +#include +#include + +template +auto to_vector(R&& r) { + std::vector> 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(e)); + } + + return v; +} + +#endif