1#ifndef STAN_MATH_PRIM_FUNCTOR_FILTER_MAP_HPP
2#define STAN_MATH_PRIM_FUNCTOR_FILTER_MAP_HPP
17template <
template <
typename...>
class Filter,
typename T>
19 static constexpr bool value = Filter<T>::value;
22template <
template <
typename...>
class Filter,
typename... Types>
28template <
template <
typename...>
class Filter,
typename T,
typename... VecArgs>
31 = Filter<std::vector<T, VecArgs...>>
::value
42template <
template <
typename...>
class Filter,
typename T>
71template <
template <
typename...>
class Filter,
bool InVector =
false,
72 bool InTuple =
false,
typename F,
typename T>
73inline constexpr decltype(
auto)
filter_map(F&& f, T&& x) {
74 if constexpr (inspect_tuple_v<Filter, T>) {
75 if constexpr (is_tuple_v<T>) {
77 [&f](
auto&&... args) {
79 f, std::forward<
decltype(args)>(args))...);
92 if constexpr (InTuple) {
97 }
else if constexpr (is_std_vector_v<T>) {
104 std::vector<decltype(filter_map<Filter, true>(f, x[0]))> ret;
105 for (
size_t i = 0; i < x.size(); ++i) {
106 ret.push_back(filter_map<Filter, true>(f, x[i]));
112 if constexpr (InVector) {
115 return std::make_tuple(std::move(ret));
118 if constexpr (InVector) {
119 return std::forward<F>(f)(std::forward<T>(x));
125 if constexpr (InVector) {
126 return std::forward<F>(f)(std::forward<T>(x));
132 return std::make_tuple();
152template <
template <
typename...>
class Filter,
typename F,
typename T,
153 require_tuple_t<T>* =
nullptr>
155 return internal::filter_map<Filter>(std::forward<F>(f), std::forward<T>(x));
constexpr decltype(auto) filter_map(F &&f, T &&x)
Filter a tuple and apply a functor to each element that passes the filter.
constexpr bool inspect_tuple_v
Check if a tuple or type contains a tuple that passes the filter.
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.
constexpr decltype(auto) filter_map(F &&f, T &&x)
Filter a tuple and apply a functor to each element that passes the filter.
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Check if the type is a tuple or contains a tuple.
static constexpr bool value