From 561e2ad09aea21aaf6c74fdddc4b71beb935d917 Mon Sep 17 00:00:00 2001
From: Olivier Stasse <olivier.stasse@laas.fr>
Date: Mon, 6 Feb 2023 11:09:49 +0100
Subject: [PATCH] Forward declaration of << operator for
 dynamicgraph::timestamp_t GCC accept this but according to C++ standard this
 is not correct. CLANG does not accept it.

---
 src/fwd.hpp           | 45 +++++++++++++++++++++++++++++++++++++++++++
 src/ros_subscribe.cpp |  2 ++
 src/ros_subscribe.hpp |  1 +
 src/time_point_io.hpp | 28 ++-------------------------
 4 files changed, 50 insertions(+), 26 deletions(-)
 create mode 100644 src/fwd.hpp

diff --git a/src/fwd.hpp b/src/fwd.hpp
new file mode 100644
index 0000000..878b347
--- /dev/null
+++ b/src/fwd.hpp
@@ -0,0 +1,45 @@
+/**
+ * @file
+ * @license BSD 3-clause
+ * @copyright Copyright (c) 2023, LAAS/CNRS
+ * @copyright Copyright (c) 2020, New York University and Max Planck
+ * Gesellschaft
+ *
+ * @brief Define the time stamp signal.
+ */
+
+#pragma once
+
+#include <ostream>
+#include <chrono>
+
+namespace dynamic_graph_bridge
+{
+/** @brief Time stamp type. */
+typedef std::chrono::time_point<std::chrono::high_resolution_clock> timestamp_t;
+
+}  // namespace dynamic_graph_bridge
+
+namespace dynamicgraph
+{
+/**
+ * @brief out stream the time stamp data.
+ *
+ * @param os
+ * @param time_stamp
+ * @return std::ostream&
+ *
+ * For clang this function needs to be forward declared before the template using it.
+ * This is more in accordance to the standard.
+ */
+inline std::ostream &operator<<(
+    std::ostream &os, const dynamic_graph_bridge::timestamp_t &time_stamp)
+{
+    std::chrono::time_point<std::chrono::high_resolution_clock,
+                            std::chrono::milliseconds>
+        time_stamp_nanosec =
+            std::chrono::time_point_cast<std::chrono::milliseconds>(time_stamp);
+    os << time_stamp_nanosec.time_since_epoch().count();
+    return os;
+}
+}
diff --git a/src/ros_subscribe.cpp b/src/ros_subscribe.cpp
index 9d65b3d..0f787ad 100644
--- a/src/ros_subscribe.cpp
+++ b/src/ros_subscribe.cpp
@@ -7,6 +7,7 @@
  * @date 2019-05-22
  */
 
+#include "fwd.hpp"
 #include <dynamic-graph/factory.h>
 #include "ros_subscribe.hpp"
 
@@ -163,6 +164,7 @@ Add::Add(RosSubscribe& entity, const std::string& doc_string)
 
 Value Add::doExecute()
 {
+  using namespace dynamicgraph;
     RosSubscribe& entity = static_cast<RosSubscribe&>(owner());
     std::vector<Value> values = getParameterValues();
 
diff --git a/src/ros_subscribe.hpp b/src/ros_subscribe.hpp
index 5f361be..c00bfa9 100644
--- a/src/ros_subscribe.hpp
+++ b/src/ros_subscribe.hpp
@@ -10,6 +10,7 @@
 
 #pragma once
 
+#include "fwd.hpp"
 #include <dynamic-graph/command.h>
 #include <dynamic-graph/entity.h>
 #include <dynamic-graph/signal-ptr.h>
diff --git a/src/time_point_io.hpp b/src/time_point_io.hpp
index 0827b07..d9260f7 100644
--- a/src/time_point_io.hpp
+++ b/src/time_point_io.hpp
@@ -9,36 +9,12 @@
 
 #pragma once
 
-#include <dynamic-graph/signal-caster.h>
-
-#include <chrono>
+#include "fwd.hpp"
 
-namespace dynamic_graph_bridge
-{
-/** @brief Time stamp type. */
-typedef std::chrono::time_point<std::chrono::high_resolution_clock> timestamp_t;
-
-}  // namespace dynamic_graph_bridge
+#include <dynamic-graph/signal-caster.h>
 
 namespace dynamicgraph
 {
-/**
- * @brief out stream the time stamp data.
- *
- * @param os
- * @param time_stamp
- * @return std::ostream&
- */
-inline std::ostream &operator<<(
-    std::ostream &os, const dynamic_graph_bridge::timestamp_t &time_stamp)
-{
-    std::chrono::time_point<std::chrono::high_resolution_clock,
-                            std::chrono::milliseconds>
-        time_stamp_nanosec =
-            std::chrono::time_point_cast<std::chrono::milliseconds>(time_stamp);
-    os << time_stamp_nanosec.time_since_epoch().count();
-    return os;
-}
 
 /**
  * @brief Structure used to serialize/deserialize the time stamp.
-- 
GitLab