A
Alex Vinokur
Is boost::lexical_cast<>() always bijective?
In other words:
// --------------------------------------
template <class From, class To>
bool type_cast (const From& i_from, To& o_to)
{
bool ret = true;
try
{
o_to = boost::lexical_cast<To>(i_from);
}
catch(boost::bad_lexical_cast &)
{
ret = false;
}
return ret;
}
// --------------------------
T1 t1 = <some value>;
T2 t2;
if (type_cast (t1, t2))
{
assert (type_cast (t2, t1)); // does it always succeed?
}
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
In other words:
// --------------------------------------
template <class From, class To>
bool type_cast (const From& i_from, To& o_to)
{
bool ret = true;
try
{
o_to = boost::lexical_cast<To>(i_from);
}
catch(boost::bad_lexical_cast &)
{
ret = false;
}
return ret;
}
// --------------------------
T1 t1 = <some value>;
T2 t2;
if (type_cast (t1, t2))
{
assert (type_cast (t2, t1)); // does it always succeed?
}
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn