@@ -16,8 +16,8 @@ namespace internal {
1616 * Filter a tuple and apply a functor to each element that passes the filter.
1717 * @note The `Filter` will only check `T` and if `T` is a tuple, it will
1818 * recursively check each element of the tuple. But it will not inspect into
19- * `std::vector` elements automatically. If you want to inspect the inner element
20- * of an `std::vector` your type trait must do that itself.
19+ * `std::vector` elements automatically. If you want to inspect the inner
20+ * element of an `std::vector` your type trait must do that itself.
2121 * @tparam Filter a struct that accepts one template parameter and has a static
2222 * constexpr bool member named value that is true if the type should be
2323 * included in the output tuple.
@@ -33,23 +33,25 @@ namespace internal {
3333 * @return a tuple with the functor applied to each element which passed the
3434 * filter.
3535 */
36- template <template <typename ...> class Filter , bool InVector = false , bool InTuple = false ,
37- typename F, typename T>
36+ template <template <typename ...> class Filter , bool InVector = false ,
37+ bool InTuple = false , typename F, typename T>
3838inline constexpr decltype (auto ) filter_map(F&& f, T&& x) {
3939 if constexpr (inspect_tuple_v<Filter, T>) {
4040 if constexpr (is_tuple_v<T>) {
41- auto ret = stan::math::apply ([&f](auto &&... args) {
42- return stan::math::tuple_concat (
43- filter_map<Filter, false , true >(f, std::forward<decltype (args)>(args))...
44- );
45- }, std::forward<T>(x));
41+ auto ret = stan::math::apply (
42+ [&f](auto &&... args) {
43+ return stan::math::tuple_concat (filter_map<Filter, false , true >(
44+ f, std::forward<decltype (args)>(args))...);
45+ },
46+ std::forward<T>(x));
4647 /* If we are in at this stage, we want tuple_concat to return a tuple here
4748 * So we return a tuple(tuple()) so that tuple_cat concats
4849 * the first layer of tuple.
49- * For example, if our input is a tuple(double, tuple(double, vec<double>))
50- * with an identity filter we want tuple_concat to return a
50+ * For example, if our input is a tuple(double, tuple(double,
51+ * vec<double>)) with an identity filter we want tuple_concat to return a
5152 * tuple(double, tuple(double, vec<double>)).
52- * Without the double tuple we would get back a tuple(double, double, vec<double>).
53+ * Without the double tuple we would get back a tuple(double, double,
54+ * vec<double>).
5355 */
5456 if constexpr (InTuple) {
5557 return partially_forward_as_tuple (std::move (ret));
@@ -77,27 +79,29 @@ inline constexpr decltype(auto) filter_map(F&& f, T&& x) {
7779 if constexpr (InVector) {
7880 return std::forward<F>(f)(std::forward<T>(x));
7981 } else {
80- return partially_forward_as_tuple (std::forward<F>(f)(std::forward<T>(x)));
82+ return partially_forward_as_tuple (
83+ std::forward<F>(f)(std::forward<T>(x)));
8184 }
8285 }
8386 } else {
8487 if constexpr (InVector) {
8588 return std::forward<F>(f)(std::forward<T>(x));
8689 } else {
87- return partially_forward_as_tuple (std::forward<F>(f)(std::forward<T>(x)));
90+ return partially_forward_as_tuple (
91+ std::forward<F>(f)(std::forward<T>(x)));
8892 }
8993 }
9094 } else {
9195 return std::make_tuple ();
9296 }
9397}
94- }
98+ } // namespace internal
9599/* *
96100 * Filter a tuple and apply a functor to each element that passes the filter.
97101 * @note The `Filter` will only check `T` and if `T` is a tuple, it will
98102 * recursively check each element of the tuple. But it will not inspect into
99- * `std::vector` elements automatically. If you want to inspect the inner element
100- * of an `std::vector` your type trait must do that itself.
103+ * `std::vector` elements automatically. If you want to inspect the inner
104+ * element of an `std::vector` your type trait must do that itself.
101105 * @tparam Filter a struct that accepts one template parameter and has a static
102106 * constexpr bool member named value that is true if the type should be
103107 * included in the output tuple.
@@ -108,11 +112,10 @@ inline constexpr decltype(auto) filter_map(F&& f, T&& x) {
108112 * @return a tuple with the functor applied to each element which passed the
109113 * filter.
110114 */
111- template <template <typename ...> class Filter ,
112- typename F, typename T, require_tuple_t <T>* = nullptr >
115+ template <template <typename ...> class Filter , typename F, typename T,
116+ require_tuple_t <T>* = nullptr >
113117inline constexpr decltype (auto ) filter_map(F&& f, T&& x) {
114- return internal::filter_map<Filter>(
115- std::forward<F>(f), std::forward<T>(x));
118+ return internal::filter_map<Filter>(std::forward<F>(f), std::forward<T>(x));
116119}
117120} // namespace math
118121} // namespace stan
0 commit comments