Skip to content

Commit db25cb6

Browse files
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.
1 parent 9308145 commit db25cb6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/signal/signal-cast-helper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ void DefaultCastRegisterer<dynamicgraph::Matrix>::trace(
7373
}
7474
}
7575

76+
// for std::string, do not check failure. If input stream contains an
77+
// empty string, iss.fail() returns true and an exception is thrown
78+
template <>
79+
inline boost::any DefaultCastRegisterer<std::string>::cast
80+
(std::istringstream &iss)
81+
{
82+
std::string inst ("");
83+
iss >> inst;
84+
return inst;
85+
}
86+
7687
/// Registers useful casts
7788
namespace {
7889
DefaultCastRegisterer<double> double_reg;

0 commit comments

Comments
 (0)