lexical_cast fails to convert std::string to boost::dynamic_bitset<>
Hi!
I am trying to convert a string to a boost::dynamic_bitset
using boost::lexical_cast, as in this example:
template <class Value>
bool GetValue(const std::string& str, Value& val)
{
try
{
val = boost::lexical_cast<Value>(str);
}
catch(boost::bad_lexical_cast&)
{
return false;
}
return true;
}
int main()
{
std::string str = "01";
boost::dynamic_bitset<> bits;
if(!GetValue(str, bits))
{
[...]
}
}
The lexical_cast always throws an exception.
The problem seems to be in lexical_cast.hpp,
where a temporary object is created:
Target result;
if(!(interpreter << arg) || !(interpreter >> result) ||
!(interpreter >> std::ws).eof())
throw bad_lexical_cast();
and in dynamic_bitset.hpp, where
operator>>(std::basic_istream
participants (1)
-
Klaus Nowikow