Wednesday, February 28, 2018

Digest for comp.lang.c++@googlegroups.com - 7 updates in 3 topics

"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Feb 28 01:40PM -0800

On 2/28/2018 12:35 PM, Rick C. Hodgin wrote:
> of substance, or seeking out solidity in things. I want to grab you by the ears
> and shake you back and forth screaming into your thinking: WAKE UP!! WAKE UP!!
> WAKE UP!!
 
Is that a threat?
 
> But I fear it would do no good. I fear you'll have to go through the
> hardest things, being hurt significantly as you go, before you will wisen up.
 
Is that some kind of other threat as well?
 
[...]
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 28 02:06PM -0800

On Wednesday, February 28, 2018 at 4:40:56 PM UTC-5, Chris M. Thomasson wrote:
> > hardest things, being hurt significantly as you go, before you will wisen up.
 
> Is that some kind of other threat as well?
 
> [...]
 
How do you conclude "threat" from what I wrote?
 
The statement is that you are so hard-headed that nothing will teach
you until go through it yourself. Life will pound you to the ground,
and then, and only then, will you begin to seek those things you
should've been seeking all along.
 
I hope I'm wrong. I hope you find out long before then.
 
I am serious, Chris. You do not realize what you're mocking with your
flippant attitude toward God. You think it's all a joke. It isn't.
These things I teach you about sin, condemnation, Hellfire, and salvation
from sin by and through Jesus Christ are real. And unless you come
to realize this for real, that final day when you stand before God
being judged will consume you.
 
I hope you get this meaning. It is no threat from me to you. It is
the way things will go for you without repentance. It will be the
final relationship you have with God Himself, and it will end very
badly for you ... unless you repent and ask forgiveness fir your sin
before that day.
 
It is my teaching to you only, the teaching that comes from the Bible,
and the teaching that is for all people. The entirety of what will
happen to you is between you and God, and whether or not you accept
Jesus Christ. Romans 12:
 
https://www.biblegateway.com/passage/?search=Romans+12%3A19&version=KJV
 
19 Dearly beloved, avenge not yourselves, but rather give
place unto wrath: for it is written, Vengeance is mine;
I will repay, saith the Lord.
 
Christians do not harm people, Chris. We warn them of the destruction
that is coming their way if they persist in the rebellion against God.
 
Good luck.
 
--
Rick C. Hodgin
"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Feb 28 03:26PM -0800

On 2/28/2018 2:06 PM, Rick C. Hodgin wrote:
>>> and shake you back and forth screaming into your thinking: WAKE UP!! WAKE UP!!
>>> WAKE UP!!
 
>> Is that a threat?
 
If we ever meet, please do not try to grab me.
 
[...]
red floyd <dont.bother@its.invalid>: Feb 28 09:52AM -0800

On 2/28/2018 3:36 AM, Jorgen Grahn wrote:
> again. The documentation in Stroustrup's book isn't enough, not for
> me anyway.
 
> ISTR that James Kanze had a web page on the subject.
 
Langer and Kreft wrote a book on it. I have it somewhere:
 
"Standard C++ IOStreams and Locales: Advanced Programmer's Guide and
Reference"
 
https://www.amazon.com/Standard-IOStreams-Locales-Programmers-Reference/dp/0201183951
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 28 08:51PM +0100

On 28.02.2018 12:16, Chris Vine wrote:
> namely when you want to construct a stream object for a pre-opened
> file descriptor. I find it surprising that, on unix-like platforms at
> least, gcc and clang do not provide built in streambuffers for this.
 
But g++ does.
 
__gnu_cxx::stdio_filebuf
 
<url: https://gcc.gnu.org/onlinedocs/gcc-4.6.2/libstdc++/api/a00069.html>
 
 
 
> So in a unix-like environment you either have to write your own
> streambuffer (which is what I have done) or you take the easier route
> of using POSIX fdopen() and C streams instead.
 
Cheers & hth.,
 
- Alf
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Feb 28 10:49PM

On Wed, 28 Feb 2018 20:51:49 +0100
 
> __gnu_cxx::stdio_filebuf
 
> <url:
> https://gcc.gnu.org/onlinedocs/gcc-4.6.2/libstdc++/api/a00069.html>
 
Ah, OK, I didn't know that. Thanks.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Feb 28 10:05PM

> std::string db;
 
> protocol://[username:password@]host[:port]/db
 
> [...] designates the optional parts
 
That looks suspiciously like an URL, or URI or whatever it's called.
Can't you rely on the formal definition in some RFC instead of
describing it vaguely yourself? You can add extra limitations if you
want to (e.g. you seem to mandate a cleartext password with the user
name)?
 
> My algorithm uses std::string::find_first_of heavily.
 
I personally don't like the std::string methods, the string::npos and
all that business. Consider using <algorithm> on begin(s) .. end(s),
which IMO feels more idiomatic.
 
> In fact I don't like it. It doesn't look clean.
 
A parser doesn't have to look clean. Dump it in a well-documented
function, and write unit tests.
 
> a standard C++ (11+ allowed) or boost (C++ standard preferred)
> Idealy would be to have only a single pass through the string.
 
> Could you please give me some hints or provide some kind of code snippet.
 
I second the recommendation of std::regex, or splitting it up a bit by
other means and then using std::regex on some of the parts.
 
But there are some issues you need to clarify for yourself (e.g. by
using an existing formal definition of the syntax; see above):
 
- Can the username:password part contain :, @ or /? That would mean
you cannot start by splitting on the third / in the string.
 
- Can the host contain a :, and how would that work with host:port?
Host names don't contain colons, but IPv6 addresses do. In an URL,
you'd write it like this [::1]:80.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Digest for comp.lang.c++@googlegroups.com - 25 updates in 4 topics

porparek@gmail.com: Feb 28 11:24AM -0800

Hi,
I would like to parse the following string to extract the following parts:
std::string unsername;
std::string host;
int port;
std::string db;
 
protocol://[username:password@]host[:port]/db
 
[...] designates the optional parts
 
My algorithm uses std::string::find_first_of heavily. In fact I don't like it. It doesn't look clean.
I wonder whether there is an efficient way of doing this using only a standard C++ (11+ allowed) or boost (C++ standard preferred)
Idealy would be to have only a single pass through the string.
 
Could you please give me some hints or provide some kind of code snippet.
 
Thanks in advance.
Paavo Helde <myfirstname@osa.pri.ee>: Feb 28 09:28PM +0200


> My algorithm uses std::string::find_first_of heavily. In fact I don't like it. It doesn't look clean.
> I wonder whether there is an efficient way of doing this using only a standard C++ (11+ allowed) or boost (C++ standard preferred)
> Idealy would be to have only a single pass through the string.
 
Take a look at <regex>: http://en.cppreference.com/w/cpp/regex
legalize+jeeves@mail.xmission.com (Richard): Feb 28 09:37PM

[Please do not mail me a copy of your followup]
 
porparek@gmail.com spake the secret code
 
>I would like to parse the following string to extract the following parts:
^^^^^
 
This is the key to your whole question. When you need to parse
something, use a parser :).
 
Options are:
0) Use an existing library
1) find a regex pattern to match your input
2) write a parser by hand
3) use a parser library
4) use a parser generator
 
My opinions on pros/cons of the above options:
 
0) Recognize that you're parsing a URL. Lots of people have already
solved this problem, so look for a library that already does this and
use it. Google "c++ url parser".
 
1) For simple things, a regex is fine, but I would put this problem as
too complicated. The regex is going to look really ugly considering
all the optional parts.
 
2) Writing a parser by hand for this shouldn't be too hard. In fact,
one shows up on stackoverflow from the above google search.
 
3) You can use Boost.Spirit to write parsers in a pretty succinct
manner. They are fast. However, other people unfamiliar with
Boost.Spirit may find your code hard to understand. If you're
comfortable with Spirit, this is an easy way to get a high quality
parser. If you're uncomfortable with Spirit (or your team is
uncomfortable), then a hand written parser may be better.
 
4) You could use YACC to generate a parser for this structure.
However, IMO it would be overkill. Debugging through YACC parsers is
pretty disgusting IMO.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
David Brown <david.brown@hesbynett.no>: Feb 28 09:59AM +0100

On 27/02/18 23:07, Real Troll wrote:
>> thrd_sleep(&(struct timespec){.tv_sec=1}, NULL); // sleep 1 sec
>> printf("Time: %s", ctime(&(time_t){time(NULL)}));
>> }
 
Works fine for me with gcc. Did you remember to use "-std=c11", or a
gcc version new enough to have "-std=gnu11" as the default? Did you use
a new enough gcc? (I think 4.9 is needed.) Did you use a library with
the right support (not a Windows gcc version that uses MS's old and
limited C libraries)?
Keith Thompson <kst-u@mib.org>: Feb 28 10:03AM -0800

> a new enough gcc? (I think 4.9 is needed.) Did you use a library with
> the right support (not a Windows gcc version that uses MS's old and
> limited C libraries)?
 
On Linux systems, gcc typically uses GNU libc by default, and GNU
libc doesn't support <threads.h>. Specifying -std=... doesn't help.
I don't think Visual Studio supports it either. (<threads.h> is
optional, so this doesn't mean these implementations are non-conforming
as long as they predefine __STDC_NO_THREADS__.)
 
On Debian-based systems, you can install an alternative C library,
MUSL, which does support <threads.h>. You have to use a wrapper
called musl-gcc to compile with it.
 
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
David Brown <david.brown@hesbynett.no>: Feb 28 10:35PM +0100

On 28/02/18 19:03, Keith Thompson wrote:
 
> On Debian-based systems, you can install an alternative C library,
> MUSL, which does support <threads.h>. You have to use a wrapper
> called musl-gcc to compile with it.
 
Oh, you are correct. The gcc I tested was using MUSL.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 28 07:15AM -0800

On Sunday, February 4, 2018 at 12:28:52 PM UTC-5, [Leigh Johnston pretending
to be Rick C. Hodgin] wrote:
> assembly of the LORD." -- Deuteronomy 23:2
 
> Jesus Christ was himself illegitimate as his Father was not married to
> the whore Mary.
 
I came across this today and wanted to address this point. There are various
teachings out there which state something like what you say above, or that
Mary was raped and therefore God is a tyrant and a brute ... but please know
the work that is in play in the world regarding the Bible. It's being targeted
by forces bent on hiding what it teaches, and for a very good reason ... because
it is the word of God and it speaks the truth. Those forces do not want people
to know the truth because the truth WILL set them free:
 
Begins at 24:56:
https://www.youtube.com/watch?v=tR_7tkC6ZiA&t=24m56s
 
"The NIV is now owned by (Rupert Murdoch) a secular publishing company.
So it's outside the hands of the Christian community. And as a matter
of fact it's with something called Harper San Francisco, which produces
very very blasphemous books about Jesus Christ saying He was a mystic,
and that His mother was raped and just horrible horrible things..."
 
-----
The facts:
 
An angel appeared to Mary to proclaim the good news. Pay special attention
to verse 38 where Mary gives her consent to that which the angel has proclaimed:
 
https://www.biblegateway.com/passage/?search=Luke+1%3A26-38&version=KJV
 
26 And in the sixth month the angel Gabriel was sent from God unto a city
of Galilee, named Nazareth,
27 To a virgin espoused to a man whose name was Joseph, of the house of
David; and the virgin's name was Mary.
28 And the angel came in unto her, and said, Hail, thou that art highly
favoured, the Lord is with thee: blessed art thou among women.
29 And when she saw him, she was troubled at his saying, and cast in her
mind what manner of salutation this should be.
==> 30 And the angel said unto her, Fear not, Mary: for thou hast found favour
with God.
31 And, behold, thou shalt conceive in thy womb, and bring forth a son, and
shalt call his name Jesus.
32 He shall be great, and shall be called the Son of the Highest: and the
Lord God shall give unto him the throne of his father David:
33 And he shall reign over the house of Jacob for ever; and of his kingdom
there shall be no end.
34 Then said Mary unto the angel, How shall this be, seeing I know not a man?
35 And the angel answered and said unto her, The Holy Ghost shall come upon
thee, and the power of the Highest shall overshadow thee: therefore also
that holy thing which shall be born of thee shall be called the Son of God.
36 And, behold, thy cousin Elisabeth, she hath also conceived a son in her
old age: and this is the sixth month with her, who was called barren.
37 For with God nothing shall be impossible.
==> 38 And Mary said, Behold the handmaid of the Lord; be it unto me according
to thy word. And the angel departed from her.
 
This declaration followed a prophesy given by God formerly, one of miraculous
construct, one which would demonstrate that Jesus, born of a virgin truly was
the Son of God, for virgins cannot have children, save by miracles given them
directly by God:
 
https://www.biblegateway.com/passage/?search=Isaiah+7%3A14&version=KJV
 
14 Therefore the Lord himself shall give you a sign; Behold, a virgin
shall conceive, and bear a son, and shall call his name Immanuel.
 
The name "Immanuel" in Hebrew means "God with us":
 
http://biblehub.com/text/isaiah/7-14.htm
http://biblehub.com/hebrew/6005.htm
 
-----
The truth is stronger than fiction and lies. It also has the unique trait of
being the only thing that's correct and foundational upon which to build.
 
If any of you want to know the truth, seek it out. When it comes to finding
God, and knowing who you are, what sin is, who He is, and why you need Him in
your life ... you will find it ... when you seek it with all your heart.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 28 04:27PM

On 28/02/2018 15:15, Rick C. Hodgin wrote:
 
> If any of you want to know the truth, seek it out. When it comes to finding
> God, and knowing who you are, what sin is, who He is, and why you need Him in
> your life ... you will find it ... when you seek it with all your heart.
 
Mary giving her consent doesn't change anything regarding Jesus Christ's
legitimacy: Mary was not married to God ergo Jesus Christ is still a
bastard.
 
But of course as Jesus is also the Father, Jesus fucked himself to give
birth to himself which makes perfect sense and isn't absurd in the
slightest.
 
#atheism
 
--
 
Thank you,
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 28 09:14AM -0800

On Wednesday, February 28, 2018 at 11:27:57 AM UTC-5, Rick C. Hodgin wrote:
> Mary giving her consent doesn't change anything regarding Jesus Christ's
> legitimacy: Mary was not married to God ergo Jesus Christ is still a
> bastard...
 
I, the real Rick C. Hodgin, did not write this post.
 
Please examine the headers to see that there is someone usurping my
identity (and without my permission). I post from Eternal September
and Google Groups only.
 
--
Rick C. Hodgin
 
PS -- Leigh, you are absolutely disgusting in your vulgarity, a true
servant of Satan's twisting lies perpetrated upon your life. It
is unbecoming for a creation of God to behave as you are choosing.
May God open your eyes to the beautiful creation you are, and lead
you into understanding and repentance for your sin.
"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Feb 28 11:07AM -0800

On 2/4/2018 9:59 AM, Rick C. Hodgin wrote:
> On 2/4/2018 12:28 PM, Rick C. Hodgin wrote:
>> "No one of illegitimate birth ...
 
> I, the real Rick C. Hodgin, did not write this post.
 
We know.
 
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 28 11:16AM -0800

On Wednesday, February 28, 2018 at 2:11:27 PM UTC-5, Chris M. Thomasson wrote:
> >> "No one of illegitimate birth ...
 
> > I, the real Rick C. Hodgin, did not write this post.
 
> We know.
 
Blind and non-forward-thinking Chris ... I do not write these messages
for you or the others here who, today, know what's happening in this
group. I write it for the unknowing soul who searches for my name on
Google and arrives at some horrid blasphemy perpetrated against me by
a Class-A coward.
 
> > Please examine the headers to see that there is someone usurping my
> > identity (and without my permission).  I post from Eternal September
> > and Google Groups only.
 
There is true, foundational wisdom that exists, Chris. Seek it.
 
--
Rick C. Hodgin
"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Feb 28 11:55AM -0800

On 2/28/2018 11:16 AM, Rick C. Hodgin wrote:
>>> identity (and without my permission).  I post from Eternal September
>>> and Google Groups only.
 
> There is true, foundational wisdom that exists, Chris. Seek it.
 
Wow, you really are a nice guy... ;^o
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Feb 28 12:35PM -0800

On Wednesday, February 28, 2018 at 2:55:39 PM UTC-5, Chris M. Thomasson wrote:
> Wow, you really are a nice guy... ;^o
 
You're so... flippant, Chris. Casual about everything. Never considering things
of substance, or seeking out solidity in things. I want to grab you by the ears
and shake you back and forth screaming into your thinking: WAKE UP!! WAKE UP!!
WAKE UP!! But I fear it would do no good. I fear you'll have to go through the
hardest things, being hurt significantly as you go, before you will wisen up.
 
One of the hardest things for me in this world is to know that no matter how
much I try and teach people the truth, with all the varying ways from simple
instruction to figuratively grabbing people by the ears and shaking them as I
indicated above ... some people will not be saved.
 
It breaks my heart. It's such a waste. And it's all lost to pride.
 
--
Rick C. Hodgin
"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Feb 28 12:40PM -0800

On 2/28/2018 12:35 PM, Rick C. Hodgin wrote:
> and shake you back and forth screaming into your thinking: WAKE UP!! WAKE UP!!
> WAKE UP!! But I fear it would do no good. I fear you'll have to go through the
> hardest things, being hurt significantly as you go, before you will wisen up.
 
Shi% Just a matter of time?
 
scott@slp53.sl.home (Scott Lurndal): Feb 28 09:34PM

"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
It's such a waste. And it's all lost to pride.
 
Indeed, your Hubris is astonishing.
Juha Nieminen <nospam@thanks.invalid>: Feb 28 05:45AM

> whether either of the two ways of doing this was noticeably superior to
> the other. What I've learned is that they're pretty similar for this
> kind of task.
 
Understanding <iostream> is ok, but be aware that most, if not all,
implementations of it are less efficient than those of <cstdio>.
Even std::istream::read() can be less efficient than std::fread(),
even though logically they do the exact same thing.
Melzzzzz <Melzzzzz@zzzzz.com>: Feb 28 05:58AM

> implementations of it are less efficient than those of <cstdio>.
> Even std::istream::read() can be less efficient than std::fread(),
> even though logically they do the exact same thing.
 
Why?
 
--
press any key to continue or any other to quit...
Hergen Lehmann <hlehmann.expires.5-11@snafu.de>: Feb 28 09:23AM +0100

Am 28.02.2018 um 06:45 schrieb Juha Nieminen:
 
> implementations of it are less efficient than those of <cstdio>.
> Even std::istream::read() can be less efficient than std::fread(),
> even though logically they do the exact same thing.
 
Another problem with <iostream> is that it does too good a job in hiding
the underlying file handle.
It is fine for basic file IO in simple single-process/single-user
applications, but in "real life" you will quickly run in into situations
where you need more control over the opening mode, need to set runtime
flags like record locks, or need to operate on non-file streams like
sockets. <iostream> can't do that, at least not without re-inventing the
wheel (by writing your own streambuf with it's highly complex and
awkward interface).
Ian Collins <ian-news@hotmail.com>: Feb 28 10:17PM +1300

On 02/28/2018 09:23 PM, Hergen Lehmann wrote:
> sockets. <iostream> can't do that, at least not without re-inventing the
> wheel (by writing your own streambuf with it's highly complex and
> awkward interface).
 
On the contrary, it is a very simple interface... I often use
specialised streambuf implementations as a teaching example. All that
is required for an underflow() override.
 
--
Ian.
Paavo Helde <myfirstname@osa.pri.ee>: Feb 28 12:01PM +0200

On 28.02.2018 7:58, Melzzzzz wrote:
>> Even std::istream::read() can be less efficient than std::fread(),
>> even though logically they do the exact same thing.
 
> Why?
 
I just stepped through a std::ifstream::read() in the MSVC++2017
debugger. In addition to an indirection (stream -> readbuf) it calls the
following virtual functions:
 
virtual streamsize basic_streambuf::xsgetn();
virtual int_type basic_filebuf::uflow();
 
xsgetn() is called once and uflow() is called when the read buffer gets
empty. So it's not so bad (I have an impression some other std::istream
features involve virtual calls per each character).
 
Underneath it uses the FILE* infrastructure, but does not use any public
FILE* functions for reading the bulk of the data; instead it uses the
internal read buffer in the FILE structure directly.
 
In short: std::ifstream::read() is built on top of FILE* mechanism with
some indirections and virtual calls added. As such, it cannot be faster
than fread(); if it is slower depends on a lot of things, most probably
the actual I/O speed will be the bottleneck anyway, but YMMV. And in
another implementation ifstream::read() might be implemented differently.
 
If the file is in the disk cache then the ifstream::read() overhead
seems to matter to some extent. I made a test reading a 8MB binary file
repeatedly and summing each 128-th byte, the results are (I also added
mmap/MapViewOfFile for curiosity):
 
istream::read: 3.48344 ms
fread: 2.09826 ms
mmap: 0.990501 ms
 
Cheers
Paavo
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Feb 28 11:16AM

On Wed, 28 Feb 2018 22:17:07 +1300
 
> On the contrary, it is a very simple interface... I often use
> specialised streambuf implementations as a teaching example. All
> that is required for an underflow() override.
 
I agree that std::basic_streambuf is a reasonably designed and
simple-ish interface to implement. The bare minimum is to inherit from
std::basic_streambuf and override sync() and overflow() for output and
underflow() for input. If you want the most efficient block reads and
writes which bypass the internal buffers you might also want to
override xsputn() and xsgetn(), and you are also going to have to
override seekoff() and seekpos() if you want to implement seekability
on seekable files (irrelevant for things like sockets of course).
 
My objection is more having to do it at all for the most common case,
namely when you want to construct a stream object for a pre-opened
file descriptor. I find it surprising that, on unix-like platforms at
least, gcc and clang do not provide built in streambuffers for this.
The built-in streams provided by C++ do not actually enable you to
write a safe temporary file.
 
So in a unix-like environment you either have to write your own
streambuffer (which is what I have done) or you take the easier route
of using POSIX fdopen() and C streams instead.
 
Chris
Jorgen Grahn <grahn+nntp@snipabacken.se>: Feb 28 11:36AM

On Wed, 2018-02-28, Ian Collins wrote:
 
> On the contrary, it is a very simple interface... I often use
> specialised streambuf implementations as a teaching example. All that
> is required for an underflow() override.
 
You should teach us ... I've spent a lot of time on it, then barely
understood enough to to implement something useful -- and forgotten it
again. The documentation in Stroustrup's book isn't enough, not for
me anyway.
 
ISTR that James Kanze had a web page on the subject.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Feb 28 12:32PM

On 28 Feb 2018 11:36:29 GMT
> again. The documentation in Stroustrup's book isn't enough, not for
> me anyway.
 
> ISTR that James Kanze had a web page on the subject.
 
Josuttis's "The C++ Standard Library" gives an introduction and sample
implementation, which isn't bad (or at least the first edition does, I
don't have the second).
Melzzzzz <Melzzzzz@zzzzz.com>: Feb 28 12:52PM


> istream::read: 3.48344 ms
> fread: 2.09826 ms
> mmap: 0.990501 ms
 
Heh, I always use fstream/sstream, didn't know that this is that slower
;)
I even implemented simple database exclusivelly with fstream ;p
And parsing strings , I don't like snprintf/sscanf at all ;)
 
 
--
press any key to continue or any other to quit...
Paavo Helde <myfirstname@osa.pri.ee>: Feb 28 04:15PM +0200

On 28.02.2018 14:52, Melzzzzz wrote:
 
> Heh, I always use fstream/sstream, didn't know that this is that slower
> ;)
> I even implemented simple database exclusivelly with fstream ;p
 
Depends on the usage. If the file is not in the OS disk cache the
timings would probably be much longer and more equal. Also, whenever the
program does something more substantial with the file content then it
also does not matter if there is a millisecond lost somewhere.
 
> And parsing strings , I don't like snprintf/sscanf at all ;)
 
snprintf,sscanf et al are locale sensitive, meaning that a substantial
part of their work is spent on setting up and locking the global locale.
This can become significant in a massively multithreaded app. At least
C++ streams have the imbue() functionality for binding a non-global
locale which ought to remove this particular bottleneck.
 
Of course, if locale dependency is not needed at all, like when parsing
source code of a typical programming language, the most performing way
is to use special functions with built-in ASCII/C-locale behavior. But
again, all this matters only if the speed is important at that point.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

台灣婦女会文章在今天報上(Times-Picayune)。請去買報!

Dear Jessica: The article about the NATWA Louisiana Chapter is in

TODAY's Times-Picayune (D10).

Please buy a TODAY.

THANK YOU for the news.

Happy New Year
Tina



Sent from my iPad

台灣婦女会文章在今天報上(Times-Picayune)。請去買報!

Dear Jessica: The article about the NATWA Louisiana Chapter is in

TODAY's Times-Picayune (D10).

Please buy a TODAY.

THANK YOU for the news.

Happy New Year
Tina



Sent from my iPad

Tuesday, February 27, 2018

Digest for comp.lang.c++@googlegroups.com - 10 updates in 4 topics

"James R. Kuyper" <jameskuyper@verizon.net>: Feb 27 08:30AM -0500

On 02/22/2018 07:48 PM, Egor wrote:
>> I thought C++11 introduced sleep_for(). Why not use the standard function?
> OP posted the question to both comp.lang.c and comp.lang.c++, so I
> provided a C-oriented answer.
 
A C-oriented answer using C2011 could use thrd_sleep()
Keith Thompson <kst-u@mib.org>: Feb 27 09:07AM -0800

>> OP posted the question to both comp.lang.c and comp.lang.c++, so I
>> provided a C-oriented answer.
 
> A C-oriented answer using C2011 could use thrd_sleep()
 
It could, but support for the C11 <threads.h> is still uncommon.
 
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Real Troll <Real.Troll@Trolls.com>: Feb 27 06:07PM -0400

On 27/02/2018 13:30, James R. Kuyper wrote:
>> OP posted the question to both comp.lang.c and comp.lang.c++, so I
>> provided a C-oriented answer.
 
> A C-oriented answer using C2011 could use thrd_sleep()
 
This one doesn't even compile in any of the compiler I have tried:
 
GNU G++,
Embarcadero
Visual Studio 2010, 2013, 2015, 2017
 
Juha Nieminen <nospam@thanks.invalid>: Feb 27 07:17AM

> In C, I'd use fread() and check the return value for a short read.
 
There's nothing wrong in using std::fread() in C++. It's a perfectly
legit standard function.
"James R. Kuyper" <jameskuyper@verizon.net>: Feb 27 08:52AM -0500

On 02/27/2018 02:17 AM, Juha Nieminen wrote:
>> In C, I'd use fread() and check the return value for a short read.
 
> There's nothing wrong in using std::fread() in C++. It's a perfectly
> legit standard function.
 
Yes, I understand that. However, most of <cstdio> has equivalent
functionality within <iostream>, and I want to properly understand what
the <iostream> way of doing such things is. In particular, I was curious
whether either of the two ways of doing this was noticeably superior to
the other. What I've learned is that they're pretty similar for this
kind of task.
The code I'm working on right now is not code that I'm entirely free to
change as I desire - there's a couple of different versions of the
program, and when I make my fix to our version, the people responsible
for the other versions will find it easier to incorporate my fix if it
doesn't require them to switch from <iostream> to <cstdio>. I'd guess
that if I did deliver <cstdio>-based code, they'd assume that I was a C
programmer doing so due to my ignorance of <iostream> (which is mostly -
but not entirely - wrong).
alessio211734 <alessio211734@yahoo.it>: Feb 27 01:19AM -0800

Thanks
alessio211734 <alessio211734@yahoo.it>: Feb 27 01:19AM -0800

Thanks you
alessio211734 <alessio211734@yahoo.it>: Feb 27 01:43AM -0800

> "\n";
> }
> }
 
Hello, nice solution and if I want the possibity to have a circular buffer and for example print if this it's the buffer.
std::vector<float> v={1,2,3};
output:
1 2
2 3
3 1
How can I modify the template to get an iterator to circular buffer?
Paavo Helde <myfirstname@osa.pri.ee>: Feb 27 01:03PM +0200

On 27.02.2018 11:43, alessio211734 wrote:
> 2 3
> 3 1
> How can I modify the template to get an iterator to circular buffer?
 
Circular is slightly more tricky. Currently the IterPair class is
holding 2 iterators which are just incremented in operator++. One could
also store the container begin() and end() in the IterPair class and if
it2_ reaches the end, wrap it over to begin.
 
Cheers
Paavo
Juha Nieminen <nospam@thanks.invalid>: Feb 27 07:19AM

> This is my last post on this forum
 
How many times have we seen this?
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Digest for comp.programming.threads@googlegroups.com - 1 update in 1 topic

Kaz Kylheku <217-679-0842@kylheku.com>: Feb 26 07:14PM

>> > d. something else I haven't thought of?
 
>> It must work.
 
> Well, I realize that's what the docs seem to imply, but…
 
The docs clearly require it; if it doesn't work, it's
an implementation bug.
 
>> contrast, the PTHREAD_MUTEX_INITIALIZER is described as a macro
>> that can be used for initialization, and not a constant.
 
> Sure, but when I assign it, I am doing nothing to ensure that assignment is visible to all threads before they call pthread_once on it. Therefore it seemed plausible that another core's cache still contains some other value for that memory location, and a thread running on that core and calling pthread_once would see the uninitialized value instead of PTHREAD_ONCE_INIT, and skip calling the initialization function, which would be a problem…
 
This depends on how the threads acquire the pointer to this entire
object that contains the "pthread_once_t".
 
Suppose that we dynamically allocate "struct point { int x, y; }"
and initialize x and y, then pass this on to other threads.
 
How do we ensure that the memory is synchronized so that threads
see the stable values of x and y?
 
Whatever approaches works for these x and y is applicable to the
initialization of a pthread_once_t.
 
If we just allocate an object, initialize it, put its pointer
into an unprotected shared variable which another thread notices
has become non-null and uses it, and do not execute any memory
barriers, then we have a problem on some machines.
 
If some synchronization is involved then we should be okay. E.g.
consumer is waiting on a condition variable for the pointer to
materialize and then uses it.
 
static obj *ptr; // assumed initially null
 
// producer
new_object->once = PTHREAD_ONCE_INIT;
pthread_mutex_lock(&mut);
ptr = new_object;
pthread_mutex_unlock(&mut);
pthread_cond_broadcast(&cond);
 
// consumer
pthread_mutex_lock(&mut);
while (ptr == 0)
pthread_cond_wait(&cond, &mut);
pthread_mutex_unlock(&mut);
pthread_once(&ptr->once, init_fun);
 
Here, the memory synchronizing properties of the mutex ensure
that all the assignments done prior to the producer's
pthread_mutex_unlock call are visible at the time the consumer
acquires the mutex and finds ptr not to be null.
 
The consumer cannot find a non-null ptr, such that
ptr->once has not yet been initialized.
 
If you don't use synchronization like this when introducing the pointer
to the other threads, then you're on your own; but it's not really an
issue of the pthread_once, but rather an issue of the the reordering of
the loads and stores of "ptr" and "ptr->once".
 
 
> Hm, you make a good point. But you know how tricky races are; I
> wouldn't count on all that exercise to have flushed out a bug if this
> issue wasn't totally considered.
 
But, come to think of it, is this situation really protected in all
circumstances?
 
Suppose thread A obtains a handle with dlopen, passes it unsafely to
thread B (e.g. just puts it into a shared location where B picks it up,
no mutexes).
 
Is it guaranteed that B can use dlsym, etc, to read the stable value of
a global variable variable?
 
I think, if so, it's only because some mutexes are incidentally used
inside dlopen, like to insert the library into some global list
of loaded libraries.
 
[I apologize for this topical interruption and now return you to the
regular deluge of drivel by the local troll.]
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.programming.threads+unsubscribe@googlegroups.com.

Monday, February 26, 2018

Digest for comp.lang.c++@googlegroups.com - 7 updates in 2 topics

alessio211734 <alessio211734@yahoo.it>: Feb 26 12:28PM -0800

Hello,
many time happen to do a series of similar algorithms where loop through array with adjacent iterator. Just a example to better understand
 
std::vector<float> v;
auto l=v.begin();
auto c=v.begin();
c++;
while (c!=v.end())
{
// here I do something with (*l) and (*c)
l++;
c++
}
 
how can I avoid to do a sort of copy and paste on my code when should
loop through array with adjacent iterator and apply a generic algoritm on the value of this iterator?
I think something with template but I don't known how.
Daniel <danielaparker@gmail.com>: Feb 26 01:16PM -0800

On Monday, February 26, 2018 at 3:29:25 PM UTC-5, alessio211734 wrote:
 
> }
 
> how can I avoid to do a sort of copy and paste on my code when should
> loop through array with adjacent iterator and apply a generic algoritm on > the value of this iterator?
 
Perhaps something like
 
#include <vector>
#include <iostream>
 
template <class Iterator,class F>
void process(Iterator l, Iterator end, F f)
{
if (l != end)
{
auto c = l + 1;
while (c != end)
{
f(c, l);
c++;
l++;
}
}
}
 
int main()
{
std::vector<float> v = {1,2,3};
 
auto f = [](std::vector<float>::iterator c,
std::vector<float>::iterator l)
{
std::cout << "do something with " << *c << " and " << *l <<
std::endl;
};
 
process(v.begin(), v.end(), f);
}
Daniel <danielaparker@gmail.com>: Feb 26 01:22PM -0800

On Monday, February 26, 2018 at 4:16:39 PM UTC-5, Daniel wrote:
 
> Perhaps something like
 
or
 
#include <vector>
#include <iostream>
 
template <class Iterator,class F>
void process(Iterator l, Iterator end, F f)
{
if (l != end)
{
auto c = l + 1;
while (c != end)
{
f(*c, *l);
c++;
l++;
}
}
}
 
int main()
{
std::vector<float> v = {1,2,3};
 
auto f = [](float c, float l)
{std::cout << "do something with " << c << " and " << l << std::endl; };
process(v.begin(), v.end(), f);
}
Paavo Helde <myfirstname@osa.pri.ee>: Feb 26 11:47PM +0200

On 26.02.2018 22:28, alessio211734 wrote:
 
> how can I avoid to do a sort of copy and paste on my code when should
> loop through array with adjacent iterator and apply a generic algoritm on the value of this iterator?
> I think something with template but I don't known how.
 
My attempt without lambdas:
 
#include <iostream>
#include <vector>
#include <numeric>
#include <cassert>
 
template<class CONT>
class IterPair {
public:
using T = typename CONT::value_type;
using ITER = typename CONT::const_iterator;
 
IterPair(ITER it1, ITER it2) : it1_(it1), it2_(it2) {
}
std::pair<const T&, const T&> operator*() const {
return std::pair<const T&, const T&>(*it1_, *it2_);
}
bool operator!=(const IterPair& b) {
return it1_ != b.it1_ && it2_ != b.it2_;
}
void operator++() {
++it1_;
++it2_;
}
private:
ITER it1_, it2_;
};
 
template<class CONT>
class AdjacentIterWrapper {
public:
using const_iterator = IterPair<CONT>;
AdjacentIterWrapper(const CONT& c) : c_(c) {
assert(!c.empty());
}
const_iterator begin() {
return const_iterator(c_.begin(), c_.begin()+1);
}
const_iterator end() {
return const_iterator(c_.end(), c_.end());
}
private:
const CONT& c_;
};
 
template<class CONT>
AdjacentIterWrapper<CONT> IterateAdjacent(const CONT& c) {
return AdjacentIterWrapper<CONT>(c);
}
 
int main() {
std::vector<float> v(100);
std::iota(v.begin(), v.end(), 0.0f);
 
for (auto x: IterateAdjacent(v)) {
// here I do something with (*l) and (*c)
std::cout << "do something with " << x.first << " and " << x.second <<
"\n";
}
}
"Öö Tiib" <ootiib@hot.ee>: Feb 26 01:49PM -0800

On Monday, 26 February 2018 22:29:25 UTC+2, alessio211734 wrote:
 
> how can I avoid to do a sort of copy and paste on my code when should
> loop through array with adjacent iterator and apply a generic algoritm on the value of this iterator?
> I think something with template but I don't known how.
 
Vector has random access iterators so with those you can do
arithmetic and also since C++11 those have dereference operator [].
 
if (v.empty())
{
abort(); // or whatever is appropriate by your program logic
}
for (auto it = v.begin()+1; it!=v.end(); ++it)
{
// here do something with your it[-1] and it[0]
}
Daniel <danielaparker@gmail.com>: Feb 26 02:13PM -0800

On Monday, February 26, 2018 at 4:50:11 PM UTC-5, Öö Tiib wrote:
> {
> // here do something with your it[-1] and it[0]
> }
 
Hard to beat that :-)
Vir Campestris <vir.campestris@invalid.invalid>: Feb 26 09:56PM

On 23/02/2018 22:27, Alf P. Steinbach wrote:
 
> You can wrap it in a class that doesn't have default constructor.
 
> Static check better than dynamic. ;-)
 
That might do it. I'll have a play next time I have some free time.
 
Fixing core bugs in shared code isn't my real job - I'm working on a
specific product - but I do seem to have found a few over the months
I've been here.
 
Thanks Alft & Öö.
 
Andy
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

Fwd: [EXTERNAL] Fwd: 絕世好文


Subject: 絕世好文!

 

建議您花3-5秒存一下,受益一輩子!中老年朋友必讀

 

2017-12-28 健康資深公民

 

(01)  人靜時,躺下來仔細想想,人活著真不容易,

         明知以後會死,還要努力的活著,人活一輩子到底是為什麼!?

 

複雜的社會,看不透的人心,放不下的牽掛,經歷不完的酸甜苦辣,走不完的坎坷,越不過的無奈,忘不了的昨天,忙不完的今天,想不到的明天,最後不知道會消失在哪一天!這就是人生。

所以再忙再累別忘了心疼自己,冬天已到,天氣己冷,一定要記得好好照顧自己!

 

(02)人生如天氣,可預料,但往往出乎意料!?

 

不管是陽光燦爛,還是聚散無常,一份好心情,是人生唯一不能被剝奪的財富。

把握好每天的生活,照顧好獨一無二的身體,就是最好的珍惜。

得之坦然,失之泰然,隨性而往,隨遇而安,一切隨緣,是最豁達而明智的人生態度。

 

(03)    多好的一段話:

 

我們都有缺點,所以彼此包容一點。

我們都有優點,所以彼此欣賞一點。

我們都有個性,所以彼此謙讓一點。

我們都有差異,所以彼此接納一點。

我們都有傷心,所以彼此安慰一點。

我們都有快樂,所以彼此分享一點。

因為我們有緣相識,請珍惜生命中的每一位家人、朋友!開心的過好每一天!

 

(04)    十年後,您把現在的奔馳寶馬給孩子,他們會說太舊了!

 

十年後,您把現在的蘋果6s給孩子,他們會說別逗了!

十年後,你躺在病床上抱著一堆存摺,要兒女天天給你把屎端尿,兒女們會說,僱保姆吧!

十年後,你保持了健康的體魄,還能到處旅遊,打拳、跳舞。

您的孩子會說,老爸老媽你們太明智了!

 

●    給孩子最好的禮物是自己的健康!

 

重要的事情,再說一遍,請大家記住最後一句話:

 

●    給孩子最好的禮物是保養好自己的身心健康。

 

人生就是做好兩件事:

 

第一,教育好孩子,不要危害社會;

第二是照顧好自己,別拖累孩子。

 

(05)    請大家看看,著名的廈門大學教授易中天的一段話,好經典!!

 

再過若干年,我們都將離去,對這個世界來說,我們徹底變成了虛無。

 

●    我們奮鬥一生,帶不走一草一木。我們執著一生,帶不走一分虛榮愛慕。

 

今生,無論貴賤貧富,總有一天都要走到這最後一步。到了天國,驀然回首,我們的這一生,形同虛度!!

 

●    所以,從現在起,我們要用心生活,天天開心快樂就好。

 

三千繁華,彈指剎那,百年之後,不過一捧黃沙。

 

※請善待每個人,因為沒有下輩子。

 

(06)    一輩子真的好短,有多少人說好要過一輩子,可走著走著就剩下了曾經。

 

又有多少人說好要做一輩子的朋友,可轉身就成為最熟悉的陌生人。有的明明說好明天見,可醒來就是天各一方。

所以,趁我們都還活著,戰友、同學、朋友、同事、能相聚就不要錯過,能愛時就認真的愛,能擁抱時就擁入懷,能牽手時就不放開。能玩的時候玩,能吃的時候吃。

 

(07)    請好好珍惜身邊的人,不要做翻臉比翻書還快的人。

 

互相理解才是真正的感情,不要給你的人生留下太多的遺憾。再好的緣份也經不起敷衍,再深的感情也需要珍惜。

沒有絕對的傻瓜,只有願為你裝傻的人。原諒你的人,是不願失去你。真誠才能永相守,珍惜才配長擁有。

 

(08)    有利時,不要不讓人;有理時,不要不饒人;有能時,不要嘲笑人。

 

太精明遭人厭;太挑剔遭人嫌;太驕傲遭人棄。

 

●    人在世間走,本是一場空,何必處處計較,步步不讓。

 

話多了傷人,恨多了傷神,與其傷人又傷神,不如不煩神。

一輩子就圖個無愧於心,悠然自在。世間的理爭不完,爭贏了失人心;世上的利賺不盡,差不多就行。財聚人散,財散人聚。

 

(09)    心幸福,日子才輕鬆;人自在,一生才值得!

 

●    想的太多,容易煩惱;在乎太多,容易困擾;追求太多,容易累倒。

 

好好珍惜身邊的人,因為沒有下輩子的相識!好好感受生活的樂,因為轉瞬就即逝!好好體會生命的每一天,因為只有今生,沒有來世。

 

這是一篇難得的絕世好文!

 

獻給家人,老師,同學,同事、戰友、好朋友,

好弟兄,好姐妹,以及愛我的和我愛的人。

 

讀過的,若能再讀一次,

沒准讓你自己體會人生真諦。