On 2 May, 19:45, "Niels Dekker - no return address"
<nore...@[EMAIL PROTECTED]
> wrote:
> Tony (aka "Guinness Tony") wrote:
<snip>
> > // partial specializationss
> > template<class traits>
> > basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&,
> ...
>
> > [how odd - I've never noticed that "specializationss" typo before!]
>
> Actually those overloaded operator<< functions aren't even template
> specializations! In 2001 it was already noticed by Andy Sawyer: LWG
issue 311
> "Incorrect wording in basic_ostream class
synopsis"http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#311
Indeed, but that resolution didn't seem to make it into the
2003 revised standard (from which I quoted the declarations.)
<snip>
> Interesting!!! That could be a source of very nasty bugs, especially
when
> switching from one library implementation to another!
All library implementations should follow the standard and
thus behave in a consistent (if surprising) manner. Some
pre-standard libraries implemented the (char const*)
inserters as members, but surely we are talking about
standards-conformant implementations, here? Even the
still-all-too-popular MSVC++6's library implements them
as non-members (although the compiler silently permits
binding of tem****aries to non-const references, so
int i = 42;
std::string s = static_cast<std::ostringstream&>(
std::ostringstream() << "i = " << i).str();
....actually works with that compiler, producing the
"expected" result, for all the wrong reasons!)
> Still, why do you think the "flush trick" is superior to creating a
> "tem****ary" lvalue by means of a wrapper?
Sorry - I didn't mean to claim superiority; I just
wanted to add an alternative solution to the mix.
> Do you have any references, showing
> that the "flush trick" is indeed a well-known idiom?
Well, I recall having first encountered it in a
discussion in one of the clc++/clc++m newsgroups,
presented by one of the regulars. After a bit of
searching, I've finally discovered that thread:
http://groups.google.co.uk/group/comp.lang.c++.moderated/browse_thread/thread/28f0226f8809eff5/
To my chagrin, I see now that Alf introduced it as
"a nasty trick" and James questioned whether it is
a "clean" solution. How my memory plays tricks!
"Idiomatic" is certainly not a description of
this technique and I retract my use of that term.
"A curiosity" is probably nearer the mark.
> (I wonder how many
> people actually /know/ that std::flush is inserted by a member function,
while
> other objects, e.g., strings, are inserted by non-member functions.)
Alf's original presentation of this method actually
used the ostream::flush() member function (why didn't
I remember it that way?), so knowledge of how
std::flush() is inserted becomes moot.
> Otherwise I think I'll stick to the wrapper...
I think that's probably for the best!
Regards,
Tony.
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|
30 Posts in Topic:
|
"Niels Dekker - no r |
2008-04-23 13:14:37 |
|
Martin York <Martin.Yo |
2008-04-24 01:05:54 |
|
Peter Jones <dev-null@ |
2008-04-24 01:10:33 |
|
Carl Barron <cbarron41 |
2008-04-24 01:43:21 |
|
Vidar Hasfjord <vattil |
2008-04-24 15:12:53 |
|
Brendan <catphive@[EMA |
2008-04-24 15:43:20 |
|
Brendan <catphive@[EMA |
2008-04-25 10:22:59 |
|
Niels Dekker - no return |
2008-04-26 08:46:24 |
|
Carl Barron <cbarron41 |
2008-04-27 07:13:20 |
|
Brendan Miller <catphi |
2008-04-27 07:29:25 |
|
Vidar Hasfjord <vattil |
2008-04-27 07:29:42 |
|
Vidar Hasfjord <vattil |
2008-04-28 01:56:19 |
|
Vidar Hasfjord <vattil |
2008-04-28 02:13:22 |
|
vova777@[EMAIL PROTECTED] |
2008-04-28 16:06:27 |
|
"Niels Dekker - no r |
2008-04-28 16:01:35 |
|
guinness.tony@[EMAIL PROT |
2008-04-28 16:01:50 |
|
"Hendrik Schober&quo |
2008-04-28 20:35:47 |
|
Vidar Hasfjord <vattil |
2008-04-29 10:38:48 |
|
Brendan Miller <catphi |
2008-04-29 10:43:23 |
|
Vidar Hasfjord <vattil |
2008-04-29 10:43:23 |
|
Vidar Hasfjord <vattil |
2008-04-29 10:43:22 |
|
vova777@[EMAIL PROTECTED] |
2008-04-29 12:13:56 |
|
Vidar Hasfjord <vattil |
2008-04-29 17:41:45 |
|
Niels Dekker - no return |
2008-04-30 10:26:51 |
|
vova777@[EMAIL PROTECTED] |
2008-04-30 10:39:18 |
|
Vidar Hasfjord <vattil |
2008-04-30 17:04:43 |
|
guinness.tony@[EMAIL PROT |
2008-05-01 13:12:58 |
|
"Niels Dekker - no r |
2008-05-02 12:45:30 |
|
guinness.tony@[EMAIL PROT |
2008-05-07 11:43:29 |
|
"Niels Dekker - no r |
2008-05-08 21:29:05 |
|