Skip to content

Commit 304f929

Browse files
authored
Merge pull request #2926 from stan-dev/fix/stan-print-forward-decl
Add forward declaration to stan_print.hpp
2 parents 2e87eca + ba47378 commit 304f929

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

stan/math/prim/fun/stan_print.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ void stan_print(std::ostream* o, const EigMat& x) {
5252
*o << ']';
5353
}
5454

55+
// forward decl to allow the next two overloads to call each other
56+
template <typename T, require_tuple_t<T>* = nullptr>
57+
void stan_print(std::ostream* o, const T& x);
58+
5559
template <typename T, require_std_vector_t<T>* = nullptr>
5660
void stan_print(std::ostream* o, const T& x) {
5761
*o << '[';
@@ -64,7 +68,7 @@ void stan_print(std::ostream* o, const T& x) {
6468
*o << ']';
6569
}
6670

67-
template <typename T, require_tuple_t<T>* = nullptr>
71+
template <typename T, require_tuple_t<T>*>
6872
void stan_print(std::ostream* o, const T& x) {
6973
*o << '(';
7074
constexpr auto tuple_size = std::tuple_size<std::decay_t<T>>::value;

test/unit/math/prim/fun/stan_print_test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ TEST(MathPrim, basic_print) {
1111

1212
std::tuple<Eigen::VectorXd, int, std::vector<double>> tup(v, i, a);
1313

14+
std::vector<std::tuple<Eigen::VectorXd, int, std::vector<double>>> arr_tup{
15+
tup, tup};
16+
1417
{
1518
std::stringstream s;
1619
stan::math::stan_print(&s, i);
@@ -52,6 +55,11 @@ TEST(MathPrim, basic_print) {
5255
stan::math::stan_print(&s, tup);
5356
EXPECT_TRUE(s.str().find("([1],1,[1])") != std::string::npos);
5457
}
58+
{
59+
std::stringstream s;
60+
stan::math::stan_print(&s, arr_tup);
61+
EXPECT_TRUE(s.str().find("[([1],1,[1])") != std::string::npos);
62+
}
5563
}
5664

5765
TEST(MathPrim, basic_expressions) {

0 commit comments

Comments
 (0)