Re: [boost] Report from Berlin C++ Standards Committee meeting

David Abrahams wrote:
"Beman Dawes" <bdawes@acm.org> writes:
* Boost Lexical Cast has been tentatively accepted by the LWG for TR2.
Was there any discussion of the to_string(x) and string_to<T>(x) alternative?
That would be better than the current lexical_cast, provided that there are also basic_string and wstring vresions, i.e.: to_basic_string< CharT, CharTraits, Allocator >( x ) to_wstring(x) The string_to<T> function could have basic_string and wstring overloads, but this would be inconsistent with the rest of the C++ library. As has been mentioned, the to_string methods will not fail conversion. However, it is unclear what to do with string_to that may fail. There are two possible interfaces: 1. throw an exception on failure, like is currently done with lexical_cast 2. provide a boolean or enumeration for failure type (not-EOS, read-fail, etc.) For the second interface, it has been suggested to use something like: bool string_to<T>(x, ret) where ret is an output reference. However, this doesn't allow for the simple one-line interface that lexical_cast provides. Drawing influence from Python, I suggest that the non-throwing version look like: std::pair<T,bool> string_to<T>(x) allowing: fn( string_to<Object>(object).first );
I only ask because I remember the issue coming up somewhere before, and I have never seen a use for lexical_cast that didn't have a string on one end.
Yes. Java, Python and other languages have conversion to strings built in to their framework so classes can provide their own mechanism for converting to a string. In C++, the generic case is 3 lines: std::ostringstream ss; ss << object; fn( ss.str()); compared to the single line above. - Reece _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

On 4/11/06, Reece Dunn <msclrhd@hotmail.com> wrote: []
The string_to<T> function could have basic_string and wstring overloads, but this would be inconsistent with the rest of the C++ library.
I don't like the idea of the user having to convert whichever string he happens to use to std::basic_string just to do the conversion.

"Reece Dunn" <msclrhd@hotmail.com> writes:
Drawing influence from Python, I suggest that the non-throwing version look like:
std::pair<T,bool> string_to<T>(x)
allowing:
fn( string_to<Object>(object).first );
How does that draw influence from Python? That interface doesn't allow for types that can't be default constructed. optional<T> string_to<T>(x) seems more likely. -- Dave Abrahams Boost Consulting www.boost-consulting.com

Yuval Ronen wrote:
David Abrahams wrote:
optional<T> string_to<T>(x)
FWIW, I like to_string()/string_to() A LOT more than lexical_cast<>. IMO all of the deficiencies of lexical_cast<> are becasue it supposedly pretends to do much more than it actually does in practice. That is, it's definition is too general (convert anything to anything via a stream) while in practice is used mostly (if not exclusively) for to/from string conversions. IMO to_string/string_to allows the semantics of these functions to be narrowed down amd focused in a way that permits implementations to fullfill the most important requirements: closure (round_tripping), efficiency and robustness (optional result in the string_to case).
Yes, looks good. What is the status of optional<T> w.r.t to the standard, anyway? I hope it's on its way...
It was proposed for the Mont Tremblant meetting and it was generally well recieved. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1878.htm Unfortunately, one of the critical issues raised during the meeting, the semantics of asignment of optional references, still needs to be properly addressed, so there is no updated revision yet. -- Fernando Cacciola SciSoft http://fcacciola.50webs.com/

Yuval Ronen <ronen_yuval@yahoo.com> writes:
David Abrahams wrote:
optional<T> string_to<T>(x)
seems more likely.
Yes, looks good. What is the status of optional<T> w.r.t to the standard, anyway? I hope it's on its way...
Same old story. Write a proposal, please. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (5)
-
David Abrahams
-
Fernando Cacciola
-
Maxim Yegorushkin
-
Reece Dunn
-
Yuval Ronen