forked from intel/cpp-std-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.hpp
More file actions
44 lines (36 loc) · 1.37 KB
/
array.hpp
File metadata and controls
44 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <array>
#include <type_traits>
#include <utility>
namespace stdx {
inline namespace v1 {
template <typename D = void, typename... Ts>
constexpr auto make_array(Ts &&...ts) {
if constexpr (not std::is_void_v<D>) {
return std::array<D, sizeof...(Ts)>{std::forward<Ts>(ts)...};
} else if constexpr (sizeof...(Ts) == 0) {
return std::array<int, 0>{};
} else {
using A = std::common_type_t<Ts...>;
return std::array<A, sizeof...(Ts)>{std::forward<Ts>(ts)...};
}
}
template <template <auto> typename D, typename T, T... Is>
constexpr auto make_array(std::integer_sequence<T, Is...>) {
using A = std::remove_const_t<decltype(D<T{}>::value)>;
return std::array<A, sizeof...(Is)>{D<Is>::value...};
}
template <template <auto> typename D, auto N> constexpr auto make_array() {
return make_array<D>(std::make_integer_sequence<decltype(N), N>{});
}
template <typename T, T... Is, typename F>
constexpr auto make_array(std::integer_sequence<T, Is...>, F &&f) {
using A = std::remove_const_t<decltype(f.template operator()<T{}>())>;
return std::array<A, sizeof...(Is)>{f.template operator()<Is>()...};
}
template <auto N, typename F> constexpr auto make_array(F &&f) {
return make_array(std::make_integer_sequence<decltype(N), N>{},
std::forward<F>(f));
}
} // namespace v1
} // namespace stdx