Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2007-01-28 13:52:54

john_at_[hidden] wrote:
> I am having some trouble with lexical_cast that I think illustrates
> a problem with the underlying implementation. My basic
> problem is that I'd like lexical_cast to "work" for user-defined
> types (UDTs) that conform to lexical_cast's documented specification of
> OutputStreamable, InputStreamable, CopyConstructible and
> DefaultConstructible.
[ skiped ]

> std::istream& operator>>(std::istream& s, Udt& u){
> return s >> u.a >> u.b;
> }

I believe that this implementation is incorrect. If you put a writespace
in output operator, you should be prepared for skipws flag and read the
writespace explicitly:

std::istream& operator>>(std::istream& s, Udt& u){
    s >> u.a;
    if((s.flags() & std::ios_base::skipws) == 0)
        char whitespace;
        s >> whitespace;
    return s >> u.b;

Alexander Nasonov
There comes a time in every rightly constructed boy`s life when he
has a raging desire to go somewhere and dig for hidden treasure.
-- Henry Kissinger --
This quote is generated by: 
	/usr/pkg/bin/curl -L         \
	  | sed -e 's/^document\.write(.//' -e 's/.);$/ --/'  \
	        -e 's/<[^>]*>//g' -e 's/^More quotes from //' \
	  | fmt | tee ~/.signature-quote

Boost list run by bdawes at, gregod at, cpdaniel at, john at