Norman J. Goldstein <
nor...@telus.net> wrote:
> On 02/14/2015 03:02 PM, Jorgen Grahn wrote:
> > On Sat, 2015-02-14, Jens Thoms Toerring wrote:
> >> Norman J. Goldstein <
nor...@telus.net> wrote:
> >>> operator>>( istream&,const char* ) succeeds if the extracted characters
> >>> exactly match the supplied const char*. Leading white space is ignored.
> >>> I find this a convenient way to help parse a file.
> >>
> >> Thank you for the clarification. It's the one hazards of
> >> operator overloading I see that different people may have
> >> different ideas about what it's meant to do...
> >
> > People complain too much about operator overloading sometimes ... but
> > here I have to admit I don't like it. If I see "is >> foo", I'm going
> > to assume it follows the standard pattern -- because a std::istream is
> > involved, not just because of the ">>".
> >
> Both of you make good points -- and I agree with you. The risk of name
> clash can be mitigated by putting the overloaded operator into a
> namespace. As for usefulness, the following code is quite descriptive
> for parsing a text file:
> string varName;
> int varValue;
> is >> varName >> ":=" >> varValue >> ";";
In this context it definitely looks much more "natural" than
in your original example, which made me a bit nervous;-) A
nice example that not just the "look" of the oberload itself
but also how it's used in its "natural habitat" can be quite
important in giving an impression of what it will do. I'd
probably still prefer to have a look at the definition, but
when I see it used like this I have some idea what to expect.