Line data Source code
1 0 : // 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/TMPL.hpp"
11 : #include "Utilities/TypeTraits.hpp"
12 :
13 : /*!
14 : * \brief Constructs a `std::vector` containing arguments passed in.
15 : *
16 : * This is useful as it allows in-place construction of a vector of non-copyable
17 : * objects.
18 : *
19 : * \example
20 : * \snippet Utilities/Test_MakeVector.cpp make_vector_example
21 : */
22 : template <class ValueType = void, class Arg0, class... Args>
23 1 : auto make_vector(Arg0&& arg_0, Args&&... remaining_args) {
24 : std::vector<
25 : tmpl::conditional_t<std::is_same_v<ValueType, void>, Arg0, ValueType>>
26 : return_vector;
27 : return_vector.reserve(sizeof...(Args) + 1);
28 : return_vector.emplace_back(std::forward<Arg0>(arg_0));
29 : (void)std::initializer_list<int>{
30 : (((void)return_vector.emplace_back(std::forward<Args>(remaining_args))),
31 : 0)...};
32 : return return_vector;
33 : }
34 :
35 : template <class T>
36 0 : std::vector<T> make_vector() {
37 : return {};
38 : }
|