src: Robust make_array implementation
This is meant to be used for ints, but unfortunately std::forward is not constexpr in C++11.
This commit is contained in:
parent
1e96a2d357
commit
bff59e09dc
|
@ -45,10 +45,15 @@ make_unique(size_t size) {
|
||||||
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
|
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename... Rest>
|
// std::forward is conexpr since C++14
|
||||||
std::array<T, sizeof...(Rest)+1> make_array(T &&t, Rest &&... rest) {
|
template <typename... T>
|
||||||
return std::array<T, sizeof...(Rest)+1>{
|
constexpr std::array<
|
||||||
{std::forward<T>(t), std::forward<Rest>(rest)...}};
|
typename std::decay<typename std::common_type<T...>::type>::type,
|
||||||
|
sizeof...(T)>
|
||||||
|
make_array(T &&... t) {
|
||||||
|
return std::array<
|
||||||
|
typename std::decay<typename std::common_type<T...>::type>::type,
|
||||||
|
sizeof...(T)>{{std::forward<T>(t)...}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, size_t N> constexpr size_t array_size(T (&)[N]) {
|
template <typename T, size_t N> constexpr size_t array_size(T (&)[N]) {
|
||||||
|
|
Loading…
Reference in New Issue