Loading [MathJax]/extensions/TeX/AMSmath.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
tuple_concat.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUNCTOR_TUPLE_CONCAT_HPP
2#define STAN_MATH_PRIM_FUNCTOR_TUPLE_CONCAT_HPP
3
6#include <functional>
7#include <tuple>
8#include <utility>
9
16namespace stan {
17namespace math {
18namespace internal {
19
20template <typename Tuple1, typename Tuple2, std::size_t... I1,
21 std::size_t... I2>
22inline auto constexpr tuple_concat_impl(Tuple1&& x, Tuple2&& y,
23 std::index_sequence<I1...> /* i */,
24 std::index_sequence<I2...> /* j */) {
25 return make_holder_tuple(std::get<I1>(std::forward<Tuple1>(x))...,
26 std::get<I2>(std::forward<Tuple2>(y))...);
27}
28
29template <typename Tuple1, typename Tuple2, typename Tuple3, std::size_t... I1,
30 std::size_t... I2, std::size_t... I3>
31inline auto constexpr tuple_concat_impl(Tuple1&& x, Tuple2&& y, Tuple3&& z,
32 std::index_sequence<I1...> /* i */,
33 std::index_sequence<I2...> /* j */,
34 std::index_sequence<I3...> /* k */) {
35 return make_holder_tuple(std::get<I1>(std::forward<Tuple1>(x))...,
36 std::get<I2>(std::forward<Tuple2>(y))...,
37 std::get<I3>(std::forward<Tuple3>(z))...);
38}
39} // namespace internal
40
46inline constexpr auto tuple_concat() noexcept { return std::make_tuple(); }
47
53template <typename Tuple>
54inline auto tuple_concat(Tuple&& x) noexcept {
55 return std::forward<Tuple>(x);
56}
57
66template <typename Tuple1, typename Tuple2>
67inline auto tuple_concat(Tuple1&& x, Tuple2&& y) {
69 std::forward<Tuple1>(x), std::forward<Tuple2>(y),
70 std::make_index_sequence<std::tuple_size<std::decay_t<Tuple1>>{}>{},
71 std::make_index_sequence<std::tuple_size<std::decay_t<Tuple2>>{}>{});
72}
73
85template <typename Tuple1, typename Tuple2, typename Tuple3>
86inline auto tuple_concat(Tuple1&& x, Tuple2&& y, Tuple3&& z) {
88 std::forward<Tuple1>(x), std::forward<Tuple2>(y), std::forward<Tuple3>(z),
89 std::make_index_sequence<std::tuple_size<std::decay_t<Tuple1>>{}>{},
90 std::make_index_sequence<std::tuple_size<std::decay_t<Tuple2>>{}>{},
91 std::make_index_sequence<std::tuple_size<std::decay_t<Tuple3>>{}>{});
92}
93
105template <typename Tuple1, typename Tuple2, typename... OtherTuples>
106inline auto tuple_concat(Tuple1&& x, Tuple2&& y, OtherTuples&&... args) {
107 return tuple_concat(
108 tuple_concat(std::forward<Tuple1>(x), std::forward<Tuple2>(y)),
109 std::forward<OtherTuples>(args)...);
110}
111
125template <typename Tuple1, typename Tuple2, typename Tuple3,
126 typename... OtherTuples>
127inline auto tuple_concat(Tuple1&& x, Tuple2&& y, Tuple3&& z,
128 OtherTuples&&... args) {
129 return tuple_concat(
130 tuple_concat(std::forward<Tuple1>(x), std::forward<Tuple2>(y),
131 std::forward<Tuple3>(z)),
132 std::forward<OtherTuples>(args)...);
133}
134} // namespace math
135} // namespace stan
136
137#endif
auto constexpr tuple_concat_impl(Tuple1 &&x, Tuple2 &&y, std::index_sequence< I1... >, std::index_sequence< I2... >)
constexpr auto make_holder_tuple(Types &&... args)
Holds ownership of rvalues and forwards lvalues into a tuple.
constexpr auto tuple_concat() noexcept
Base case to pass a tuple forward.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...