5 #ifndef V8_BASE_TEMPLATE_UTILS_H_ 6 #define V8_BASE_TEMPLATE_UTILS_H_ 20 template <
class Function, std::size_t... Indexes>
23 template <
class Function, std::size_t... Indexes>
25 constexpr
static std::array<typename std::result_of<Function(size_t)>::type,
26 sizeof...(Indexes) + 1>
28 return {{f(0), f(Indexes)...}};
32 template <
class Function, std::size_t FirstIndex, std::size_t... Indexes>
44 template <std::
size_t Size,
class Function>
45 constexpr std::array<typename std::result_of<Function(size_t)>::type, Size>
47 static_assert(Size > 0,
"Can only create non-empty arrays");
54 template <
typename T,
typename... Args>
55 std::unique_ptr<T> make_unique(Args&&... args) {
56 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
64 template <
typename T,
bool remove_array_extend = true>
66 using noref_t =
typename std::remove_reference<T>::type;
67 using decay_t =
typename std::conditional<
68 std::is_array<noref_t>::value && !remove_array_extend, noref_t,
69 typename std::decay<noref_t>::type>::type;
70 using type =
typename std::conditional<std::is_scalar<decay_t>::value ||
71 std::is_array<decay_t>::value,
72 decay_t,
const decay_t&>::type;
76 template <
typename T,
typename =
void>
80 << std::declval<T>()))>
85 template <
typename Func,
typename T,
typename... Ts>
87 static_assert(
sizeof...(Ts) == 0,
"this is the base case");
88 using result_t =
typename std::remove_reference<T>::type;
89 static constexpr
T&& fold(Func func,
T&& first) {
90 return std::forward<T>(first);
94 template <
typename Func,
typename T1,
typename T2,
typename... Ts>
96 using folded_t =
typename std::result_of<Func(T1, T2)>::type;
98 using result_t =
typename next_fold_helper::result_t;
99 static constexpr result_t fold(Func func, T1&& first, T2&& second,
101 return next_fold_helper::fold(
102 func, func(std::forward<T1>(first), std::forward<T2>(second)),
103 std::forward<Ts>(more)...);
110 template <
typename Func,
typename... Ts>
111 constexpr
auto fold(Func func, Ts&&... more) ->
114 std::forward<Ts>(more)...);
118 template <
typename... Ts>
122 template <
typename T>
124 template <
typename T,
typename... Ts>
130 #endif // V8_BASE_TEMPLATE_UTILS_H_