Boost logo

Boost :

From: Stewart, Robert (stewart_at_[hidden])
Date: 2002-01-25 10:05:43

From: Björn Karlsson [SMTP:bjorn.karlsson_at_[hidden]]
> Consider what happens with a reference version:
> std::string source="11";
> int target=17;
> boost::lexical_convert(source, target); // If I don't know the correct
order, the compiler still assumes I do.
> boost::lexical_convert(target, source); // If I don't know the correct
order, the compiler still assumes I do.

Of course. Hmmm. How about this:


The idea is that lexical_convert() returns an object that defines operator
->() that returns an object that will take a non-const reference to some
type for the conversion. I don't think this would be a problem to
implement, but then I haven't tried it!

This would eliminate all ambiguity about direction, using fairly obvious
syntax. The interesting thing is that the final conversion logic invoked
would not be in lexical_convert(), so lexical_convert() and lexical_cast()
can use the same underlying functions to do the conversion, simplifying the
earlier concern about whether lexical_cast() should be implemented in terms
of lexical_convert().

> Anyway, I think a strong reason for not touching the name of
> lexical_cast.hpp is to avoid breaking existing code.

That's certainly a strong rationale. I guess if this gets standardized,
it'll be moved somewhere else anyway!

Susquehanna International Group, LLP

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