Providing a string-to-X feature
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.
Yyou might want to take a look at using facets to add the extra options needed to control input/output through << and >> http://stdcxx.apache.org/doc/stdlibug/25-1.html
From: JDlugosz@TradeStation.com To: boost-users@lists.boost.org Date: Wed, 23 Jun 2010 12:30:23 -0400 Subject: [Boost-users] Providing a string-to-X feature
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_________________________________________________________________ Een netbook met Windows 7? Hier vind je alles dat je moet weten. http://www.windows.nl/netbook
Yes, I'm currently using facets with the ISO8601 output of times, to control various options. From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Daniel Bradburn Sent: Thursday, June 24, 2010 1:56 AM To: boost users mailing list Subject: Re: [Boost-users] Providing a string-to-X feature Yyou might want to take a look at using facets to add the extra options needed to control input/output through << and >> 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.
participants (2)
-
Daniel Bradburn
-
John Dlugosz