1#ifndef STAN_MATH_PRIM_FUNCTOR_FOR_EACH_HPP
2#define STAN_MATH_PRIM_FUNCTOR_FOR_EACH_HPP
18template <
typename F,
typename T,
size_t... Is>
19constexpr inline auto for_each(F&& f, T&& t, std::index_sequence<Is...>) {
20 using Swallow =
int[];
21 static_cast<void>(Swallow{
22 (
static_cast<void>(std::forward<F>(f)(std::get<Is>(std::forward<T>(t)))),
31template <
typename F,
typename T1,
typename T2,
size_t... Is>
32constexpr inline auto for_each(F&& f, T1&& t1, T2&& t2,
33 std::index_sequence<Is...>) {
34 using Swallow =
int[];
35 static_cast<void>(Swallow{(
36 static_cast<void>(std::forward<F>(f)(std::get<Is>(std::forward<T1>(t1)),
37 std::get<Is>(std::forward<T2>(t2)))),
46template <
typename F,
typename T1,
typename T2,
typename T3,
size_t... Is>
47constexpr inline auto for_each(F&& f, T1&& t1, T2&& t2, T3&& t3,
48 std::index_sequence<Is...>) {
49 using Swallow =
int[];
50 static_cast<void>(Swallow{(
51 static_cast<void>(std::forward<F>(f)(std::get<Is>(std::forward<T1>(t1)),
52 std::get<Is>(std::forward<T2>(t2)),
53 std::get<Is>(std::forward<T3>(t3)))),
65template <
typename F,
typename T>
68 std::forward<F>(f), std::forward<T>(t),
69 std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>());
81template <
typename F,
typename T1,
typename T2>
82constexpr inline auto for_each(F&& f, T1&& t1, T2&& t2) {
83 constexpr auto t1_size = std::tuple_size<std::decay_t<T1>>::value;
84 constexpr auto t2_size = std::tuple_size<std::decay_t<T2>>::value;
85 static_assert(t1_size == t2_size,
86 "Size Mismatch between t1 and t2 in for_each");
89 std::make_index_sequence<t1_size>());
103template <
typename F,
typename T1,
typename T2,
typename T3>
104constexpr inline auto for_each(F&& f, T1&& t1, T2&& t2, T3&& t3) {
105 constexpr auto t1_size = std::tuple_size<std::decay_t<T1>>::value;
106 constexpr auto t2_size = std::tuple_size<std::decay_t<T2>>::value;
107 constexpr auto t3_size = std::tuple_size<std::decay_t<T3>>::value;
108 static_assert(t1_size == t2_size,
109 "Size Mismatch between t1 and t2 in for_each");
110 static_assert(t1_size == t3_size,
111 "Size Mismatch between t1 and t3 in for_each");
113 std::forward<T2>(t2), std::forward<T3>(t3),
114 std::make_index_sequence<t1_size>());
constexpr auto for_each(F &&f, T &&t, std::index_sequence< Is... >)
Implementation of for_each.
constexpr auto for_each(F &&f, T &&t)
Apply a function to each element of a tuple.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...