
Kevlin Henney wrote:
And that is where the problems begin. The older versions of lexical_cast had problems because they behaved like the other types that work with I/O streams... but since the other types don't work consistently or sensibly with I/O streams, this causes problems. For example, if we do as the standard does, then lexical_cast will not work when reading a single whitespace character and it will pick out the first space-separated sequence from a string. It is unlikely anyone would consider this desirable.
So, if you're going to deal with spaces, deal with them consistently and avoid surprises. And over time this is what lexical_cast has been converging on. This latest bug is one that will be fixed, continuing the trend towards total consumption of the input representation -- we thought we had it, but this corner case was missed and fixing it will improve coverage. Reverting to inconsistent behaviour is not an attractive option.
This still does not answer the real question. If I write something like istream& operator>>(istream& is, my_class& c) { return is >> c.a >> c.b; } then lexical_cast to 'my_class' won't work. Do you think it's the problem with lexical_cast, or with the above code? - Volodya