Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ah

55 views
Skip to first unread message

Alf P. Steinbach

unread,
Oct 21, 2018, 2:57:03 AM10/21/18
to
#include <iostream>

template< class Item >
auto operator,( std::ostream& stream, const Item& item )
-> std::ostream&
{
return (stream << item);
}

auto main()
-> int
{
using namespace std;
cout << "Did you know, 6*7 = ", 6*7, "! :)\n";
}

Cheers!,

- ALf

Ralf Goertz

unread,
Oct 21, 2018, 4:58:18 AM10/21/18
to
Am Sun, 21 Oct 2018 08:56:52 +0200
schrieb "Alf P. Steinbach" <alf.p.stein...@gmail.com>:
Nice. But the output

Did you know, 6*7 = 42! :)

is false since

42! =1405006117752879898543142606244511569936384000000000

SCNR

Mr Flibble

unread,
Oct 21, 2018, 12:34:46 PM10/21/18
to
Egregious for various reasons.

/Flibble

--
“You won’t burn in hell. But be nice anyway.” – Ricky Gervais

“I see Atheists are fighting and killing each other again, over who
doesn’t believe in any God the most. Oh, no..wait.. that never happens.” –
Ricky Gervais

"Suppose it's all true, and you walk up to the pearly gates, and are
confronted by God," Bryne asked on his show The Meaning of Life. "What
will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery
that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a
world that is so full of injustice and pain. That's what I would say."

woodb...@gmail.com

unread,
Oct 21, 2018, 12:52:11 PM10/21/18
to
On Sunday, October 21, 2018 at 1:57:03 AM UTC-5, Alf P. Steinbach wrote:
> #include <iostream>
>
> template< class Item >
> auto operator,( std::ostream& stream, const Item& item )

I suggest you add a space after function/operator names.


Brian
Ebenezer Enterprises - Enjoying programming again
https://github.com/Ebenezer-group/onwards

Pavel

unread,
Oct 21, 2018, 7:02:21 PM10/21/18
to
I use this trick in one of my logging libraries before variadic templates became
available, something to the form

log(logRecord, "did you know", ...);

`log' does actual formatting and flushing, `logRecord' just collects a list of
loggable items to include into the log record. This way you never forget to
flush the log and you can pass a log record to a function that does not
necessarily logs by that saving you unnecessary formatting (handy when you only
want to work on error).

my 2c
-Pavel
0 new messages