From 6288a43da7f951c6e631dbf3524f22b8864f9c1d Mon Sep 17 00:00:00 2001 From: djairoh Date: Tue, 23 Apr 2024 15:02:21 +0200 Subject: [PATCH] fix: forgot to include a file --- linear-interpolation/src/to_vector.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 linear-interpolation/src/to_vector.h 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