data-structures/cpp/build_array.cpp

18 lines
483 B
C++
Raw Permalink Normal View History

2022-09-17 04:34:05 +00:00
#include <iostream>
#include <array>
#include <type_traits>
template<typename... Args>
auto build_array(Args&&... args) -> std::array<typename std::common_type<Args...>::type, sizeof...(args)> {
using commonType = typename std::common_type<Args...>::type; // Create array
return {std::forward<commonType>(args)...};
}
int main() {
auto data {build_array(1, 0u, 'a', 3.2f, false)};
for (const auto& i : data) std::cout << i << " ";
std::cout << std::endl;
return 0;
}