Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-10 08:51:30


Gordon Woodhull wrote:
>
> I am not sure if one unified function is possible, but I wonder
> if one way to define a "best conversion" function, would be to
> drop lexical_cast's type-to-stream-to-type default, which is
> IMHO what really messes up thinking about type-to-type and
> string-to-type/type-to-string in the same sentence.
>
> And so convert_cast<T>(S) would use something like Convert if S
> or T is string (with any behavior determined by arguments), and
> something like Conversion if neither is.
>
> This is also in line with Antony Polukhin's improvements for
> lexical_cast which are mostly not lexical IIUC. I think people
> and their metaprograms expect a conversion function that is not
> actually lexical unless S or T is string.

At first blush, I agree that, without a string, there's no "lexical" in the cast. However, a UDT might contain a string and thus rely on the stream behavior and formatting. That, could, of course, be managed with a trait that indicates whether a type requires a stream for its conversion. Specializations for string types would provide the default behavior, but authors of UDTs can specialize the trait as needed.

If the trait indicates non-stream-based conversion, is it a (compile time) error to call a conversion function with manipulators, thereby implying the desire to use a stream?

With such a trait in place, the same syntax may involve a stream or not, depending upon the types involved. This fits Vladimir's idea that there need be no naming distinction between the stream-based and non-stream-based conversion functions since the trait would indicate whether a stream is needed.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk