|
Boost : |
From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2007-01-30 05:25:57
John Salmon <john <at> thesalmons.org> writes:
> Yes. It's possible to write more "defensive" inserters and
> extractors. That's beside the point. The patch allows lexical_cast
> to work with Udts whose implementations are not so careful. It does
> so while passing all existing regressions (except for two which are
> modified to return a very reasonable result rather than throwing a
> somewhat surprising exception).
I don't have an access to my home system to check if your patch doesn't
break this:
BOOST_CHECK_EQUAL(" a b c " == lexical_cast<std::string>(" a b c "));
Does it?
> Nothing in lexical_cast's documentation even hints that one should
> beware of whitespace when reading and writing from streams. There is
> no reason for lexical_cast to insist on this degree of care and
> attention to detail in the implementations of user-defined types. The
> naive pair of operator<< and operator>> in the original post work
> perfectly well when operating on iostreams in their standard, default
> state. They work perfectly well for the user who never heard of
> lexical_cast who uses the standard istringstream idiom:
>
> istringstream iss("13 19");
> Udt Foo;
> iss >> Foo;
> assert( Foo == Udt(13, 19) );
>
> Shouldn't lexical_cast do just as well? When I see something like the
> above in a colleague's code, and I suggest lexical_cast, should I
> really have to also warn him about carefully handling whitespace in
> the Udt extractor?
I'll think about it. But noskipws is there for a good reason. You can
search the boost archive.
-- Alexander Nasonov
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk