Add make_vector helper to compensate for the lack of rvalue initializer lists.

This commit is contained in:
Daniel Kirchner 2019-05-10 14:41:08 +02:00
parent e20fbd388b
commit 2046e61c26

View File

@ -346,4 +346,27 @@ inline std::string findAnyOf(std::string const& _haystack, std::vector<std::stri
return needle;
return "";
}
namespace detail
{
template<typename T>
void variadicEmplaceBack(std::vector<T>&) {}
template<typename T, typename A, typename... Args>
void variadicEmplaceBack(std::vector<T>& _vector, A&& _a, Args&&... _args)
{
_vector.emplace_back(std::forward<A>(_a));
variadicEmplaceBack(_vector, std::forward<Args>(_args)...);
}
}
template<typename T, typename... Args>
std::vector<T> make_vector(Args&&... _args)
{
std::vector<T> result;
result.reserve(sizeof...(_args));
detail::variadicEmplaceBack(result, std::forward<Args>(_args)...);
return result;
}
}