Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
make_vector_with_moved_list.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <iostream>
5#include <memory>
6#include <vector>
7
8namespace fang::stl
9{
27 template<typename T,typename ... C >
28 std::vector<T> makeVectorWithMovedList(C ... movedElement)
29 {
30 std::vector<T> vector{};
31 // Ahh lambda function
32 // Arcane fold expression magick
33
34 // So a fold expression can cary out an operation on a pack
35 // Like in math when you say 1 + 2+ ... + n
36 // In this case, the lambda expression is called a lot
37 // every time lambda ... lambda ... lambda ...
38 // I tried refactoring the labmda out but it triggered some errors
39 // so I kept it the way the post said to do.
40 // the version with for-each did not work either.
41 // I try to minimize odd shenanigans like this, but this greatly
42 // benefits the code as we have a decent amount of variants which
43 // need a vector of unique_ptr items.
44 ([&]{vector.push_back(std::move(movedElement));}(), ...);
45 FANG_ASSERT(vector.size() == sizeof...(movedElement), "Vector size must match parameter pack size");
46 return vector;
47 }
48}
#define FANG_ASSERT(CONDITION, DESC)
Definition fang_assert.hpp:24
Definition make_vector_with_moved_list.hpp:9
std::vector< T > makeVectorWithMovedList(C ... movedElement)
Definition make_vector_with_moved_list.hpp:28