MakeVector.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <initializer_list>
7 #include <utility>
8 #include <vector>
9 
10 #include "Utilities/TypeTraits.hpp"
11 
12 /*!
13  * \brief Constructs a `std::vector` containing arguments passed in.
14  *
15  * This is useful as it allows in-place construction of a vector of non-copyable
16  * objects.
17  *
18  * \example
19  * \snippet Utilities/Test_MakeVector.cpp make_vector_example
20  */
21 template <class ValueType = void, class Arg0, class... Args>
22 auto make_vector(Arg0&& arg_0, Args&&... remaining_args) {
25  return_vector;
26  return_vector.reserve(sizeof...(Args) + 1);
27  return_vector.emplace_back(std::forward<Arg0>(arg_0));
29  (((void)return_vector.emplace_back(std::forward<Args>(remaining_args))),
30  0)...};
31  return return_vector;
32 }
33 
34 template <class T>
35 std::vector<T> make_vector() {
36  return {};
37 }
Defines type traits, some of which are future STL type_traits header.