From db25cb651bc18dc11d6f801a2ca0ee56a945b1dc Mon Sep 17 00:00:00 2001
From: Florent Lamiraux <florent@laas.fr>
Date: Fri, 18 Oct 2019 10:14:51 +0200
Subject: [PATCH] Specialize template DefaultCastRegisterer<std::string>::cast

  When type is string and input istringstream contains an empty string,
  operator>> make method fail return true.
  This commit overcome this issue by not testing the result.
---
 src/signal/signal-cast-helper.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/signal/signal-cast-helper.cpp b/src/signal/signal-cast-helper.cpp
index 52c19cf..bde4ff5 100644
--- a/src/signal/signal-cast-helper.cpp
+++ b/src/signal/signal-cast-helper.cpp
@@ -73,6 +73,17 @@ void DefaultCastRegisterer<dynamicgraph::Matrix>::trace(
     }
 }
 
+// for std::string, do not check failure. If input stream contains an
+// empty string, iss.fail() returns true and an exception is thrown
+template <>
+inline boost::any DefaultCastRegisterer<std::string>::cast
+(std::istringstream &iss)
+{
+  std::string inst ("");
+  iss >> inst;
+  return inst;
+}
+
 /// Registers useful casts
 namespace {
 DefaultCastRegisterer<double> double_reg;
-- 
GitLab