Boost logo

Boost Users :

Subject: [Boost-users] Providing a string-to-X feature
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-06-22 17:08:37


Suppose I wanted to expose a "parse from string" feature for my data type. For discussion, I'll suppose it's a date/time type since everyone knows that and it illustrates the worst problems.

What is the current thought on the "best practices" way to expose this?
Maybe I'll start with a stream operator>>, and make sure it works with lexical_cast<X>(string). But, where do I add the extra options that tells it what to allow or assume when parsing? Dates for example might have different formats and it can recognize any legal format, but you can tell it to ignore some since that clashes with other input data. It contains spaces and trailing components are optional, so it doesn't know when to stop until it runs into something that doesn't fit.

In some sense, that ought to be a constructor. But it should take any kind of string-like thing or stream, and the declaration might clash with other more normal constructors, so a purpose-named "take from human-readable form" is better.

An earlier discussion touched on whether to use lexical_cast or a to_string function. This is the other direction, but might have similar issues. Only from_string doesn't seem to be as omni-present as an expectation.

Any suggestions?

--John



(big footer ahead)

TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net