From 79799c33aad95d553c7ea8a4fea974e8ac4c695d Mon Sep 17 00:00:00 2001
From: AlexanderMueller <mueller@ibb.uni-stuttgart.de>
Date: Mon, 6 Feb 2023 14:27:55 +0100
Subject: [PATCH] Fix build failure related to ProductManifold and std::cout

---
 dune/gfe/productmanifold.hh | 18 +++++++-----------
 test/targetspacetest.cc     | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/dune/gfe/productmanifold.hh b/dune/gfe/productmanifold.hh
index 52f2a848..c22f35d0 100644
--- a/dune/gfe/productmanifold.hh
+++ b/dune/gfe/productmanifold.hh
@@ -441,8 +441,13 @@ namespace Dune::GFE
       return numTS;
     }
 
-    template<class... TargetSpaces2>
-    friend std::ostream& operator<<(std::ostream& s, const ProductManifold<TargetSpaces2 ...>& c);
+    friend std::ostream& operator<<(std::ostream& s, const ProductManifold<TargetSpaces ...>& c)
+    {
+      Dune::Hybrid::forEach(Dune::Hybrid::integralRange(Dune::index_constant<ProductManifold<TargetSpaces ...>::numTS>()), [&](auto&& i) {
+        s<<Dune::className<decltype(c[i])>()<<" "<< c[i]<<"\n";
+      });
+      return s;
+    }
 
   private:
     /**
@@ -479,14 +484,5 @@ namespace Dune::GFE
 
     std::tuple<TargetSpaces ...> data_;
 };
-
-  template<typename ... TargetSpaces>
-  std::ostream& operator<<(std::ostream& s, const ProductManifold<TargetSpaces ...>& c)
-  {
-    Dune::Hybrid::forEach(Dune::Hybrid::integralRange(Dune::index_constant<ProductManifold<TargetSpaces ...>::numTS>()), [&](auto&& i) {
-        s<<Dune::className<decltype(c[i])>()<<" "<< c[i]<<"\n";
-    });
-    return s;
-  }
 }
 #endif
diff --git a/test/targetspacetest.cc b/test/targetspacetest.cc
index 8302b86d..765a46c9 100644
--- a/test/targetspacetest.cc
+++ b/test/targetspacetest.cc
@@ -337,6 +337,22 @@ void testDerivativesOfDistanceSquared(const TargetSpace& a, const TargetSpace& b
 }
 
 
+// The class ProductManifold had a bug that lead to a build failure
+// when using std::cout in the namespace Dune::GFE.
+//
+// See https://gitlab.mn.tu-dresden.de/osander/dune-gfe/-/merge_requests/114
+//
+// The following method is here to make sure that this bug does not
+// come back.
+namespace Dune::GFE
+{
+    void testUsingIOStream()
+    {
+      std::cout << "dummy text" << std::endl;
+    }
+}
+
+
 template <class TargetSpace>
 void test()
 {
-- 
GitLab