Tuesday, April 30, 2019

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

gazelle@shell.xmission.com (Kenny McCormack): Apr 30 01:15PM

In article <9f7d8f95-92e7-4af8-8fac-2a7ea7956341@googlegroups.com>,
>> And Satan invented fossils, yes?
 
>I'd answer, but you've given much evidence you won't listen to the
>answer.
 
That's never stopped you before; why start now?
 
Nobody listens to any of your crap - except to mock it.
 
--
Mike Huckabee has yet to consciously uncouple from Josh Duggar.
rick.c.hodgin@gmail.com: Apr 30 06:30AM -0700

On Tuesday, April 30, 2019 at 9:16:00 AM UTC-4, Kenny McCormack wrote:
> Nobody listens to any of your crap - except to mock it.
 
That's how you operate, Kenny, so it's natural for you to think
that's how all other people are toward others. They aren't.
 
People contact me privately and tell me that my posts have been
moving, inspirational, they ask me questions about faith, etc.
 
The posts I've made have reached people ... and it's reached the
people who it was intended for. The rest of the people mocking
my posts are already self-condemned and may never be saved.
 
-----
Now, would you like to now reply with a signature that quotes me
out of context? One applying effort toward harming my name and
reputation as a true and devout Christian?
 
You, Kenny, self-condemn your own soul as well. And the sad thing
is ... it doesn't have to be that way. But you make it that way
by your hatred of God, hatred of truth, and love of sin.
 
--
Rick C. Hodgin
gazelle@shell.xmission.com (Kenny McCormack): Apr 30 01:43PM

In article <e9074159-9eaa-4d6b-a33f-9fde7e0fa9fe@googlegroups.com>,
>> Nobody listens to any of your crap - except to mock it.
 
>That's how you operate, Kenny, so it's natural for you to think
>that's how all other people are toward others. They aren't.
 
You're a liar.
 
End of story.
 
--
It's possible that leasing office space to a Starbucks is a greater liability
in today's GOP than is hitting your mother on the head with a hammer.
rick.c.hodgin@gmail.com: Apr 30 07:21AM -0700

On Tuesday, April 30, 2019 at 9:44:06 AM UTC-4, Kenny McCormack wrote:
> >that's how all other people are toward others. They aren't.
 
> You're a liar.
 
> End of story.
 
I am not a liar. You mock most everyone you reply to, Kenny.
Even in the posts where you provide some help there is still
a mocking signature.
 
Jesus comes to the people of this world, all of them, with His
arms outstretched (literally on the cross), saying "Come to me,
all you who are heavy laden and I will give you rest for your
souls." He offers to forgive people their sin, and to give
them eternal life in Heaven.
 
What He offers is the most desirable thing imaginable for all
people everywhere ... yet because people love darkness more
than light they flee from Him, flee from His offer.
 
The Bible is available at multiple places, Kenny. You probably
even have one on a shelf somewhere, and if not there's bible.com
and 500 other Bible-related websites.
 
Anyone entering into Hell will be by their own personal choice
to go there, and not for any other reason. Each person entering
Hell will have no but themselves to blame.
 
--
Rick C. Hodgin
 
PS -- Jesus told us that because the people of the world hated Him,
they would hated by the world. Seems He was right once again.
gazelle@shell.xmission.com (Kenny McCormack): Apr 30 03:06PM

In article <5d3252ec-1599-4227-8918-21ae94fa891d@googlegroups.com>,
 
>> You're a liar.
 
>> End of story.
 
>I am not a liar. You mock most everyone you reply to, Kenny.
 
What part of "End of story" is tripping you up?
 
--
I've been watching cat videos on YouTube. More content and closer to
the truth than anything on Fox.
rick.c.hodgin@gmail.com: Apr 30 08:17AM -0700

On Tuesday, April 30, 2019 at 11:06:45 AM UTC-4, Kenny McCormack wrote:
> >> End of story.
> >I am not a liar. You mock most everyone you reply to, Kenny.
 
> What part of "End of story" is tripping you up?
 
Satan likes to put periods on things, to divide those who shine
the light from those who live in darkness. It's one of his
most effective tools because once the voice shining the light
is removed from input into one's life and ears ... then that
darkness can once again extend its clutches around the indi-
vidual and keep them on the wrong path, the one that leads to
their soul's destruction in the judgment.
 
Hopefully you'll learn: Things are true for the reasons they
are true, Kenny, and not for other reasons.
 
--
Rick C. Hodgin
rick.c.hodgin@gmail.com: Apr 30 08:42AM -0700

On Tuesday, April 30, 2019 at 11:06:45 AM UTC-4, Kenny McCormack wrote:
> >> End of story.
> >I am not a liar. You mock most everyone you reply to, Kenny.
 
> What part of "End of story" is tripping you up?
 
Something you need to learn about truth, Kenny, is it's not like
lies. The truth exists as it is always and only. It speaks with
one voice. It doesn't have alternate takes or perspectives. It
is solid, invincible, always victorious in every situation.
 
It is that truth that will defeat everyone who has sin still
charged to their soul when they leave this world. It will be
the truth of God's laws resulting in judgment and condemnation
for the souls which retain sin.
 
Jesus came to take our sin away so we can endure that total
scrutiny of truth in that final day. Without Him, we will all
fail the test and will be found guilty. Only with Him taking
our sin away from us are we able to be set free from that same
judgment and condemnation that will fall upon those who do not
have their sin taken away.
 
Jesus is not a religion.
Jesus is not a joke.
Jesus is truth, which makes Him solid, invincible, and always
victorious in every situation, including the day of your judg-
ment if you are not saved before you leave this world. He will
be glorified in every soul's destruction on that day, the same
as He will be glorified in how He gave life to all who would
receive it.
 
Every knee shall bow, and every tongue shall confess that Jesus
Christ is Lord over all, and all to the glory of God the Father.
 
You can read that personally as:
Kenny's knee will bow, and Kenny's tongue shall confess that
Jesus Christ is Lord over all, and it will be to the glory of
God the Father ... whether you do that in your repentance and
salvation, or in your rebellion against Him and your soul's
destruction in Hell.
 
The truth is not like other things. You must come to understand
what it is you're up against. You will all before it 100% every
time, Kenny. The only winning move is to recognize that while
truth will destroy your soul in Hell over sin, that same truth
is always willing to forgive your sin and set you free JUST FOR
THE ASKING. Only a rebellious fool from Hell would ignore that
free offer of salvation and choose to die a coward's death in
the unending burning flames. Only a total and complete rebellious,
idiotic fool.
 
--
Rick C. Hodgin
rick.c.hodgin@gmail.com: Apr 30 09:19AM -0700

On Tuesday, April 30, 2019 at 11:06:45 AM UTC-4, Kenny McCormack wrote:
> What part of "End of story" is tripping you up?
 
From the 1700s:
 
https://mobile.twitter.com/WhitefieldG/status/1123229014326300672
 
"Jesus died to save such as you; he is full of compassion;
and if you go to him, as poor, lost, undone sinners, Jesus
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
will give you his spirit; you shall live and reign, and
reign and live, you shall love and live, and live and love
with this Jesus to all eternity."
 
The proud will die in rebellion and enter into Hell.
 
The humble will die in repentance and will be shown grace and mercy.
 
That is truth.
 
--
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Apr 30 06:21PM +0100


> The proud will die in rebellion and enter into Hell.
 
> The humble will die in repentance and will be shown grace and mercy.
 
> That is truth.
 
Nonsense.
A) Your bible is false.
B) Your god the existence of which is predicated on your bible being true
is, given (A), also false.
 
/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."
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Apr 30 06:22PM +0100

> free offer of salvation and choose to die a coward's death in
> the unending burning flames. Only a total and complete rebellious,
> idiotic fool.
 
Nonsense.
A) Your bible is false.
B) Your god the existence of which is predicated on your bible being true
is, given (A), also false.
 
/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."
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Apr 30 06:22PM +0100

> their soul's destruction in the judgment.
 
> Hopefully you'll learn: Things are true for the reasons they
> are true, Kenny, and not for other reasons.
 
And Satan invented fossils, yes?
 
/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."
peteolcott <Here@Home>: Apr 29 06:43PM -0500

On 4/29/2019 4:53 PM, paul wallich wrote:
> would work just as well if the tag were "NPNR" or "frabjous" or "charmed" or "boogabooga". But use the tag "unsound", and magically all of the senses of "unsound" from colloguial language and other logical systems suddenly get dragged in and pasted over
> the top of what might as well be "frabjous".
 
> Do some brains need better macro systems?
 
Sound deductive inference
(a) All dogs are mammals
(b) All mammals breath
(c) Therefore all dogs breath
 
Unsound deductive inference (false premise)
(a) All dogs are office buildings
(b) All office buildings have windows
(c) Therefore all dogs have windows
 
Unsound deductive inference (invalid inference)
(a) All dogs are mammals
(b) All fish swim
(c) Therefore all dogs breath
 
 
--
Copyright 2019 Pete Olcott All rights reserved
 
"Great spirits have always encountered violent
opposition from mediocre minds." Albert Einstein
peteolcott <Here@Home>: Apr 29 09:53PM -0500

On 4/28/2019 6:36 AM, j4n bur53 wrote:
> Pure Prolog is not able to enumerate a model M,
> because it uses depth first. negation of failure
> subsequently also does cannot enumerate a model M.
 
I am not talking about every aspect of Prolog.
I am only talking about the aspect of Prolog that "understands"
that Provable(X) is True(X), Provable (¬X) is False(X).
 
From this much we can build:
(¬Provable(X) ∧ ¬Provable(¬X)) ↔ Unsound(X)
Which means that a sentence must be true or false.
 
From this we can determine that this sentence is false:
∃F ∈ Formal_System ∃G ∈ Closed_WFF(F) (G ↔ ((F ⊬ G) ∧ (F ⊬ ¬G)))
There is no sentence G of Formal System F that is neither True nor False in F.
 
Thus making this paragraph false:
First incompleteness theorem
Any consistent formal system F within which a certain amount of elementary
arithmetic can be carried out is incomplete; i.e., there are statements
of the language of F which can neither be proved nor disproved in F.
https://plato.stanford.edu/entries/goedel-incompleteness/#Int
 
Thus refuting the 1931 Incompleteness Theorem.
 
 
--
Copyright 2019 Pete Olcott All rights reserved
 
"Great spirits have always encountered violent
opposition from mediocre minds." Albert Einstein
peteolcott <Here@Home>: Apr 29 10:06PM -0500

On 4/29/2019 7:22 PM, luserdroog 0wrote:
> "dog's have bad breath."
 
> This looks almost like Aristotle's syllogisms. These
> were treated in a very interesting book by Lukasiewicz.
 
The only reason that incompleteness is provable is that the formal
proofs of symbolic logic diverge from that simple pattern.
 
Summing it up:
True(X) is Provable(X) from True Premises.
False(X) is Provable(¬X) from True Premises.
Otherwise Unsound(X).
 
Technically {Unsound} only applies to arguments and not to single
expressions of language I had to extend the meaning of the term
{Unsound} when I applied the concept of soundness to formal proofs.
 
--
Copyright 2019 Pete Olcott All rights reserved
 
"Great spirits have always encountered violent
opposition from mediocre minds." Albert Einstein
peteolcott <Here@Home>: Apr 30 11:55AM -0500

> power to be able to perform interesting inference in your system.
 
> Certainly one of Gödel's results is that if you have a formal system that is
> expressive enough to include arithmetic, you run into incompleteness.
 
Only because the mathematical system that he used to form this proof was too
weak to discern semantic ill formedness:
 
In the same way that not all finite strings are well-formed formula
(when semantic criteria is applied) not all closed WFF are logic sentences.
 
Any expression of language that is neither true nor false is
not a logic sentence of any formal system that has been
adapted to conform to the sound deductive inference model.
 
Logic sentences are always derived from sound deduction. In
the sound deductive inference model this means that there is:
[a connected sequence of valid deductions from true premises to a true conclusion].
 
When axioms are construed as expressions of language having the
semantic property of Boolean true then the theorem consequences
of formal proofs form:
[a connected sequence of inference from axioms to a true consequence].
 
In neither case is undecidability, incompleteness or inconsistency possible.
 
 
 
--
Copyright 2019 Pete Olcott All rights reserved
 
"Great spirits have always encountered violent
opposition from mediocre minds." Albert Einstein
peteolcott <Here@Home>: Apr 30 12:02PM -0500

On 4/30/2019 11:47 AM, Pascal J. Bourguignon wrote:
> inconsistent or incomplete, choose of of two.
 
> (Ie. correct programs will produce wrong results, or there will be
> programs that you won't be able to prove if it is correct or incorrect).
 
My system can express anything including arithmetic, it simply does not
do so erroneously:
 
In the same way that not all finite strings are well-formed
formula (when semantic criteria is applied) not all closed
WFF are logic sentences.
 
Any expression of language that is neither true nor false is
not a logic sentence of any formal system that has been
adapted to conform to the sound deductive inference model.
 
Logic sentences are always derived from sound deduction. In
the sound deductive inference model this means that there is:
[a connected sequence of valid deductions from true premises to a true conclusion].
 
When axioms are construed as expressions of language having the semantic
property of Boolean true (thus anchoring formal proofs in the semantics of
Boolean values) then the theorem consequences of formal proofs form:
[a connected sequence of inference from axioms to a true consequence].
 
In neither case is undecidability, incompleteness or inconsistency possible.
 
 
 
--
Copyright 2019 Pete Olcott All rights reserved
 
"Great spirits have always encountered violent
opposition from mediocre minds." Albert Einstein
peteolcott <Here@Home>: Apr 30 11:22AM -0500

In sound deductive inference there is:
[a connected sequence of valid deductions from true premises to a true conclusion].
 
It would seem that to convert formal proofs to conform to this model:
Axioms could be construed as expressions of language having the semantic
property of Boolean true. This would seem to anchor the syntax of formal
proofs within the semantics of Boolean values.
 
This would seem to cause the theorem consequences of formal proofs derive:
[a connected sequence of inference from axioms to a true consequence].
 
The key value of this transformation is that it seems to eliminate
undecidability, incompleteness and inconsistency from formal systems.
 
This defines the Prolog equivalent to sound deductive inference:
(1) Construing the Prolog database as the formal system.
(2) Construing queries that return "Yes" as True.
(3) Construing negated queries that return "Yes" as False.
(4) Construing ONLY queries that return Yes or return Yes to
their negation are sound deductive inference.
 
--
Copyright 2019 Pete Olcott All rights reserved
 
"Great spirits have always encountered violent
opposition from mediocre minds." Albert Einstein
peteolcott <Here@Home>: Apr 30 09:34AM -0500

In the same way that not all finite strings are well-formed
formula (when semantic criteria is applied) not all closed
WFF are logic sentences.
 
Any expression of language that is neither true nor false is
not a logic sentence of any formal system that has been
adapted to conform to the sound deductive inference model.
 
Logic sentences are always derived from sound deduction. In
the sound deductive inference model this means that there is:
[a connected sequence of valid deductions from true premises to a true conclusion].
 
When axioms are construed as expressions of language having the
semantic property of Boolean true then the theorem consequences
of formal proofs form:
[a connected sequence of inference from axioms to a true consequence].
 
In neither case is undecidability, incompleteness or inconsistency possible.
 
 
Eliminating Undecidability and Incompleteness in Formal Systems
https://www.researchgate.net/publication/332427635_Eliminating_Undecidability_and_Incompleteness_in_Formal_Systems
--
Copyright 2019 Pete Olcott All rights reserved
 
"Great spirits have always encountered violent
opposition from mediocre minds." Albert Einstein
Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 10:28AM +0300

On 30.04.2019 2:19, Chris M. Thomasson wrote:
> object if it does not already own one. It can if external sync is used.
> Not sure about the special case where shared_ptr will never change and
> always points to the exact same address, forever.
 
Here is a simple demo about what I had in mind. Note the lines (1) and
(2). One might argue that Wrap refcounting provides the needed external
sync here, but at least it is implicit and automatic.
 
#include <memory>
#include <iostream>
#include <thread>
#include <mutex>
 
// for serializing std::cout output only
std::mutex cout_mx;
 
struct A {
int x_;
A(int x) : x_(x) {}
~A() {
std::lock_guard<std::mutex> lock(cout_mx);
std::cout << "A destroyed\n";
}
void foo() {
std::lock_guard<std::mutex> lock(cout_mx);
std::cout << "I am A (x=" << x_ << ") in thread " <<
std::this_thread::get_id() << "\n";
}
};
 
struct Wrap {
const std::shared_ptr<A> a_; // (0) a_ is non-mutable
Wrap(int x) : a_(std::make_shared<A>(x)) {}
~Wrap() {
std::lock_guard<std::mutex> lock(cout_mx);
std::cout << "Wrap destroyed\n";
}
};
 
void OtherThread(std::shared_ptr<Wrap> wrap) {
auto a = wrap->a_; // (1) no locking
wrap.reset();
a->foo();
}
 
int main() {
auto wrap = std::make_shared<Wrap>(42);
std::thread t1(OtherThread, wrap);
auto a = wrap->a_; // (2) no locking
wrap.reset();
a->foo();
a.reset();
t1.join();
}
 
 
A possible output:
 
I am A (x=42) in thread 2216
Wrap destroyed
I am A (x=42) in thread 12512
A destroyed
Juha Nieminen <nospam@thanks.invalid>: Apr 30 10:58AM

> The problem is that the loading of the pointer and refcount increment
> need to be a single atomic op in the internals of the ref count impl.
 
It is my understanding that the control block used by std::shared_ptr
which it creates when it starts managing a new object (ie. the piece
of memory it allocates for bookkeeping) is fully thread-safe as per
the standard.
 
Which ought to mean that two separate std::shared_ptr instances that are
pointing to the same object (ie. sharing it) can freely modify eg. the
reference count for that object at the same time without problems
(which happens if they are eg. assigned to another std::shared_ptr
instance, or go out of scope, or whatever), without the programmer
having to take care of it.
 
However, the std::shared_ptr class *itself* is not thread-safe as-is
(and to make it thread-safe you need to use eg.
std::atomic<std::shared_ptr<T>>).
 
It's just a bit confusing exactly which operations, and in which situations,
are thread-safe as-is, and which are not. Some things can be done safely,
others need explicit locking (eg. by using std::atomic in C++20).
"Öö Tiib" <ootiib@hot.ee>: Apr 30 04:00AM -0700

On Monday, 29 April 2019 09:41:40 UTC+3, Juha Nieminen wrote:
> > any other thread then you have race condition. So you have
> > to put locks around it.
 
> "Write it"? Write what, exactly?
 
Write to the shared_ptr itself. It is internally designed as a
pointer. That pointer potentially points at control block (accesses
of what are synchronized). That block is either allocated together
with or potentially points at actual data (accesses of what are
again not synchronized). With "write it" I meant that pointer.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 30 02:09PM +0200

> of what are synchronized). That block is either allocated together
> with or potentially points at actual data (accesses of what are
> again not synchronized). With "write it" I meant that pointer.
 
The control-block shouldn't have the pointer to the data.
All shared_ptr's themselfes should have two pointers, one to the
control-block and one to the data. Having a concatenated pointer
to the control-block and then to the data itself would disable
out-of-order-execution, i.e. operations on the data would be
preceded by two in-order loads.
Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 03:54PM +0300

On 30.04.2019 13:58, Juha Nieminen wrote:
> (which happens if they are eg. assigned to another std::shared_ptr
> instance, or go out of scope, or whatever), without the programmer
> having to take care of it.
 
Exactly. The programmer does not need to know or care about internal
implementation details like the control block or reference counting.
 
> However, the std::shared_ptr class *itself* is not thread-safe as-is
> (and to make it thread-safe you need to use eg.
> std::atomic<std::shared_ptr<T>>).
 
Right, shared_ptr does not contain synchronization for accessing itself
because it would be both counter-productive (for pointers visible in a
single thread only), and impossible to achieve (for shared pointers).
 
E.g. consider a global shared shared_ptr:
 
std::shared_ptr<A> common_ptr = ...;
 
thread 1:
common_ptr->foo();
 
thread 2:
common_ptr = std::make_shared<A>();
 
Even if shared_ptr had internal locking and ensured that the pointer
gets replaced atomically and with proper memory barriers in thread 2,
this would still not guarantee that the pointed object is not released
and destroyed in the middle of foo() in thread 1.
 
To guarantee the proper lifetime, the operator->() should return some
kind of proxy object, which would hold the object alive until foo() is
completed. However, the standard says it returns a plain pointer, so
this cannot be done.
 
In short, shared_ptr with the current interface cannot protect against
its own modifications (not to speak about its own destruction which
could not be protected against anyway) and so external synchronization
is needed for modifications.
 
Note that refcounter sync is much easier and incurs less penalties, for
example thread 1 above does not access the refcounter at all.
 
 
> It's just a bit confusing exactly which operations, and in which situations,
> are thread-safe as-is, and which are not. Some things can be done safely,
> others need explicit locking (eg. by using std::atomic in C++20).
 
In my mind this is clear, it is safe to call any number of const member
functions in parallel, but as soon as there appears a non-const member
function call in some thread, all threads must use external sync. Chris
seems to agree, he just does not see much point in having a smartpointer
which cannot be reassigned or reset. He is probably right.
 
Anyway, all this discussion is a bit academic because shared_ptr
mechanism is meant for sharing the pointed object, not sharing the
shared_ptr itself. For passing shared_ptr pointers to other threads
there are usually better ways than to set up a global shared_ptr somewhere.
Manfred <noname@add.invalid>: Apr 30 02:19PM +0200

On 4/26/2019 3:49 PM, Öö Tiib wrote:
> So it is that combo you think?:
> https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
 
It would look like that, indeed.
It is always curious to see these things formally studied like the world
were some lab setup.
 
>> any of it.
> Oh fine. Actually it is always sort of satisfying to beat them with
> product of orders of magnitude different league instead of arguing. :D
 
Which is also anthropologically amusing - the many faces of happiness.
Juha Nieminen <nospam@thanks.invalid>: Apr 30 10:46AM


> When in 100 lines of code I see 20 times std::string, I get tired of the
> unneeded distracting details. For most people one time is enough to
> understand what is meant.
 
If you are using, for example, libpng, where every name declared by that
library has the prefix of "png_", do you "get tired" of seeing "png_" all
the time and go to lengths to get rid of it?
 
Or is it, perhaps, the case that the "png_" prefix in the names actually
makes the code easier to read and understand because you are directly seeing
where functions and types from that library are being used, in contrast with
functions and types that are not from that library?
 
I have never, ever, heard of anybody, not even the most rabid haters of
namespace prefixes, complain about seeing or having to write prefixes used
in typical C libraries like libpng and other similar ones. They are
completely fine with that (and, in fact, often use a similar naming scheme
in their own self-written libraries).
 
It's only the C++ namespace prefixes that they detest, and the psychological
phenomenon behind this difference is what puzzles me. What is the difference?
Why is one ok, but not the other? (I don't think it's a question of "_" vs
"::". That alone cannot explain the difference.)
 
> So, at the beginning I use 'using std::string' and it is clear what is meant
> with a simpe 'string' in the remainder of the scope.
 
That would be confusing. First it's "std::string", and then it's "string"?
It would look like something different.
 
Why do you oppose the idea of seeing at a quick glance where names from the
standard library are being used? What exactly is the problem? Why do you
deliberately want to make it harder to visually distinguish where such
names are being used?
 
> if I see a function "equal()" being called how do I know that it was the
> function that was defined 500 lines earlier in the same namespace?
 
If the program uses namespace prefixes consistently, then the lack of
"std::" indicates that it's not the standard library function, but something
else. It won't confuse you into thinking it's the standard library function
that's being called.
 
> Do you advocate to use the namespace prefix even within the same namespace
> in the same file?
 
When I use namespace in my own code, I usually use namespace prefixes even
when it wouldn't be needed (ie. inside functions within that same
namespace). I like to see that the name is from that namespace, even if
the code itself is also within the same namespace. It lessens the
possibility of confusion, when reading the code.
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.

Monday, April 29, 2019

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

"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Apr 29 01:07PM -0700

On 4/29/2019 3:53 AM, Paavo Helde wrote:
> and modify only the shared_ptr and weak_ptr objects themselves and not
> objects they refer to. Changes in use_count() do not reflect
> modifications that can introduce data races." ([util.smartptr.shared]).
 
The problem is that the loading of the pointer and refcount increment
need to be a single atomic op in the internals of the ref count impl.
However, if the global_ptr was guaranteed to always point to the exact
same object, and was created and fully initialized _before_ any other
thread can access it, it might be okay. Humm... But, this is basically a
singleton?
 
 
> and one has to e.g. wrap it inside a std::atomic or apply some external
> locking (std::shared_ptr::atomic_load() will be deprecated in C++20 in
> favor of std::atomic wrapping).
 
I am just not sure about the "special case" where the global_ptr is
completely setup before any threads can access it, and is guaranteed to
never change. But, why not use a singleton here?
Melzzzzz <Melzzzzz@zzzzz.com>: Apr 29 08:32PM

> same object, and was created and fully initialized _before_ any other
> thread can access it, it might be okay. Humm... But, this is basically a
> singleton?
 
No. Shared ptr is always initialized in single thread.
Having global shared ptr beats the purpose of shared ptr. In that case
raw pointer would suffice.
"Chris M. Thomasson " <ahh_f_it@crap.nothing>: Apr 29 02:25PM -0700

On 4/29/2019 1:32 PM, Melzzzzz wrote:
 
> No. Shared ptr is always initialized in single thread.
> Having global shared ptr beats the purpose of shared ptr. In that case
> raw pointer would suffice.
 
Humm... Raw pointer doesn't suffice because it would not be reference
counted? Take a deep look at differential reference counting:
 
http://www.1024cores.net/home/lock-free-algorithms/object-life-time-management/differential-reference-counting
 
Dmitry, Joe and I have worked on this in the past over on
comp.programming.threads. Have you ever seen atomic_ptr by Joe Seigh?
Here is the patent:
 
https://patents.google.com/patent/US5295262
 
The idea is to have an atomic reference counted pointer that fully works
in the following scenario:
____________________________
static atomic_ptr<foo> g_foo = new foo();
 
// thread readers
for (;;)
{
local_ptr<foo> lfoo = g_foo;
 
// can test lfoo for a null object if needed
 
lfoo->read();
}
 
// thread writers
for (;;)
{
local_ptr<foo> next_foo = new foo();
g_foo = next_foo;
}
____________________________
 
This is strong thread safety and does not work with std::shared_ptr
as-is without some external sync.
Paavo Helde <myfirstname@osa.pri.ee>: Apr 30 12:41AM +0300

On 29.04.2019 23:07, Chris M. Thomasson wrote:
> same object, and was created and fully initialized _before_ any other
> thread can access it, it might be okay. Humm... But, this is basically a
> singleton?
 
Yes, it might be a singleton. Singletons are needed sometimes. The
singleton itself would not need refcounting, but it might be needed to
pass it to interfaces which normally expect smartpointers to other,
shorter-lived objects. The singleton might play a role of a "fallback"
or "default" object in this scenario.
 
Another scenario is that the smartpointer is a non-changing member of
another shared object. The calling code copies the smartpointer member
for later use, no locking needed. Now the containing shared object can
be released safely. No singletons around.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Apr 29 04:19PM -0700

On 4/29/2019 2:41 PM, Paavo Helde wrote:
> another shared object. The calling code copies the smartpointer member
> for later use, no locking needed. Now the containing shared object can
> be released safely. No singletons around.
 
Afaict, shared_ptr does not allow a thread to take a reference to an
object if it does not already own one. It can if external sync is used.
Not sure about the special case where shared_ptr will never change and
always points to the exact same address, forever.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Apr 29 04:19PM -0700

On 4/28/2019 11:41 PM, Juha Nieminen wrote:
>> any other thread then you have race condition. So you have
>> to put locks around it.
 
> "Write it"? Write what, exactly?
 
Writing to global_ptr would be:
 
global_ptr = new foo();
 
Reading from it would be:
 
local_ptr = global_ptr.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 29 07:26PM +0200

>> Better use a unordered_map to a scalar value on which you do a switch.
 
> Why do you think unordered_map is better?
 
It's a short solution with a moderate performance.
Paavo Helde <myfirstname@osa.pri.ee>: Apr 29 10:51PM +0300

On 29.04.2019 22:19, Bart wrote:
> took zero seconds. It takes extra effort to make allowances for
> optimising compilers and makes sure you are comparing how long it takes
> to do a task, rather than how long it takes NOT to do it.
 
Right, it is definitely easier to look for the lost wallet under street
lamps only ;-)
 
> 3.5:1 for gcc-O3, compared with 3.2:1 using the original compiler, and
> 2.5:1 using gcc-O0.
 
> The perfect hash version is still slower.
 
Thanks for the numbers, these are now informative!
Christian Gollwitzer <auriocus@gmx.de>: Apr 29 11:24PM +0200

Am 29.04.19 um 19:44 schrieb Bart:
 
> This method also requires a strcmp, which I thought odd given that this
> is supposed to a perfect hash; just length compare will do as the only
> clashes are with names that are different lengths.
 
The strcmp is necessary to check that the input was indeed part of the
keywords, so that when you input "xxx" and it hashes to one of the
menaingful slots, it doesn't get interpreted as "Wednesday"
accidentally. The hash is only perfect over the set of input values. As
to the speed, I don't know, either it is only advantageous for larger
numbers of keywords or lists of words that are not separated as easily,
or perfect hashes are not as good in practice as they are in theory.
 
Maybe also looking up only always the same string is not a good
benchmark, because of the jump prediction of the processor.
 
Christian
 
Bart <bc@freeuk.com>: Apr 29 11:01PM +0100

On 29/04/2019 22:24, Christian Gollwitzer wrote:
> to the speed, I don't know, either it is only advantageous for larger
> numbers of keywords or lists of words that are not separated as easily,
> or perfect hashes are not as good in practice as they are in theory.
 
I can make it nearly double its speed by tightening it up: just doing
strcmp on the full string, rather then checking the first characters
then strcmp on the rest. And by predetermining the search string length.
 
(Note: that search does not return the 0..6 index of the original switch
version, to denote Monday to Sunday, only the original string. So here
I'm only testing for inclusion of an arbitrary string in the set, not
which one.)
 
However, a version simply doing a linear search (and which does return
the index) isn't that much worse than my tweaked perfect hash version
(it had been faster).
 
I think this data set is just too small to show the advantages of
different approaches.
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 6 topics

Jorgen Grahn <grahn+nntp@snipabacken.se>: Apr 29 07:34PM

> How to write program to find bonus? I'm beginner to learn c++.
> I have working hours and bonus but i can't write code? How i do?
 
If you're reading this:
 
I think your problem is about understanding the problem: translating
it from text to mathematics. C++ programmers cannot help you with
that part.
 
When you've gotten so far that you can express it as code (in C++,
some other language, or pseudocode) someone can help you with any
C++-specific problems.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Thiago Adams <thiago.adams@gmail.com>: Apr 29 10:03AM -0700

Let's say you want to create a switch case for strings.
 
switch (key)
{
case "Sunday": break;
case "Monday":break;
case "Tuesday": break;
case "Wednesday": break;
case "Thursday": break;
case "Friday: break;
case "Saturday": break;
}
 
I created an simple online generator for this.
http://thradams.com/switchgenerator.html
 
 
For instance (given a list of string):
 
Input:
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
 
Output:
 
int find(const char* key)
{
int result = -1;
switch (key[0])
{
case /*Friday*/ 'F' :
if (key[1]=='r' && key[2]=='i' && key[3]=='d' && key[4]=='a' && key[5]=='y' && key[6]=='\0') {
result = 0;
}
break;
case /*Monday*/ 'M' :
if (key[1]=='o' && key[2]=='n' && key[3]=='d' && key[4]=='a' && key[5]=='y' && key[6]=='\0') {
result = 1;
}
break;
case 'S':
switch (key[1])
{
case /*Saturday*/ 'a' :
if (key[2]=='t' && key[3]=='u' && key[4]=='r' && key[5]=='d' && key[6]=='a' && key[7]=='y' && key[8]=='\0') {
result = 2;
}
break;
case /*Sunday*/ 'u' :
if (key[2]=='n' && key[3]=='d' && key[4]=='a' && key[5]=='y' && key[6]=='\0') {
result = 3;
}
break;
default : break;
}
break;
case 'T':
switch (key[1])
{
case /*Thursday*/ 'h' :
if (key[2]=='u' && key[3]=='r' && key[4]=='s' && key[5]=='d' && key[6]=='a' && key[7]=='y' && key[8]=='\0') {
result = 4;
}
break;
case /*Tuesday*/ 'u' :
if (key[2]=='e' && key[3]=='s' && key[4]=='d' && key[5]=='a' && key[6]=='y' && key[7]=='\0') {
result = 5;
}
break;
default : break;
}
break;
case /*Wednesday*/ 'W' :
if (key[1]=='e' && key[2]=='d' && key[3]=='n' && key[4]=='e' && key[5]=='s' && key[6]=='d' && key[7]=='a' && key[8]=='y' && key[9]=='\0') {
result = 6;
}
break;
default : break;
}
return result;
}
Bonita Montero <Bonita.Montero@gmail.com>: Apr 29 07:08PM +0200

Better use a unordered_map to a scalar value on which you do a switch.
Thiago Adams <thiago.adams@gmail.com>: Apr 29 10:13AM -0700

On Monday, April 29, 2019 at 2:08:10 PM UTC-3, Bonita Montero wrote:
> Better use a unordered_map to a scalar value on which you do a switch.
 
Why do you think unordered_map is better?
Christian Gollwitzer <auriocus@gmx.de>: Apr 29 07:18PM +0200

Am 29.04.19 um 19:03 schrieb Thiago Adams:
 
> For instance (given a list of string):
 
> Input:
> Sunday Monday Tuesday Wednesday Thursday Friday Saturday
 
A classic tool for this task is the "perfect hash", gperf is one of the
tools. If I feed it with the same string, it outputs the code below. A
perfect hash tries to compute the correct answer in a small number of
arithmetic operations, which can be lead to very fast lookups. In cases
where performance does not matter, I'd prefer a simple linear scan. So:
 
 
std::string input = "Monday";
std::vector<std::string> wdays {"Sunday", "Monday", "tuesday", ...};
auto day = std::find(std::begin(input), std::end(input), wdays);
 
or perhaps using a std::map.
 
Or a chain of if/else blocks, which can be simplified using the
preprocessor:
 
#define OPTION(X) else if (input == #X)
 
if (false) { // NOP }
OPTION(Sunday) {
// do this
}
OPTION(Monday) {
// do that
}
 
...
#undef OPTION
 
Christian
 
 
============ code by gperf ====================================
/* C code produced by gperf version 3.0.3 */
/* Command-line:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/gperf
*/
/* Computed positions: -k'1' */
 
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
error "gperf generated tables don't work with this execution character
set. Please report a bug to <bug-gnu-gperf@gnu.org>."

Sunday, April 28, 2019

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

"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Apr 28 11:51PM +0200

On 28.04.2019 17:41, Tim Rentsch wrote:
> [snippety] In C++, _any_ program execution
> can arbitrarily misbehave, because 'resource limits' can be
> anything at all.
 
Yes.
 
As an absurd case an implementation might define type `bool` with a size
exceeding available memory. A main function with a local `bool` variable
and nothing else, could then incur Undefined Behavior.
 
 
> Definedness of behavior is about what /should/
> happen, not about what actually /will/ happen.
 
UB is about the formal hands-off area, where no requirements are imposed.
 
And vice versa.
 
When you have no rules you have UB, and when you have UB you have no rules.
 
It's actually worse. UB can be retroactive. Because, since UB is so bad,
a compiler is free to assume that UB will not occur, e.g. assuming that
a variable will never have some particular value, because that would
give UB -- then it can "optimize" away much that the programmer ordered,
and it can even produce very noticeable effects that were not ordered
and clearly not desired.
 
And that is often far too strong to appear /meaningful/ at first glance,
like getting the death penalty for jaywalking. Wtf., I'm to be executed
in the common American half-hour death struggle way for jaywalking with
no cars in sight? UB is just so much too strong that the examples in
$5/4 in C++98 and its bugfix (a.k.a. technical corrigendum) C++03 had
comments that these expressions had just unspecified effect, as if the
author, presumably Andrew Koenig, just couldn't believe the UB penalty.
 
Happily the examples and comments were non-normative text.
 
 
> Yes, running out
> of stack can result in arbitrary misbehavior. But that doesn't
> mean the standard didn't say what should have happened.
 
It doesn't.
 
It /explicitly/ doesn't say what should have happened.
 
It states that if the resource limits are not exceeded, then and only
then must the code be executed correctly; otherwise it's no
requirements, which is also known as UB-land.
 
 
>> actual effect that when I arrived at the doctor's I was all fine.
 
> I hope you have now gotten through that and are feeling much
> better.
 
Thanks, currently better, but it turned out that that little bastard was
merely hiding, redoubled it's torture efforts later, and the scans
showed that it had a brother that may become problematic (or for all I
know may already be out of my system, though Murphy's law says no).
 
 
Cheers!,
 
- Alf
Daniel <danielaparker@gmail.com>: Apr 28 11:08AM -0700

On Sunday, April 28, 2019 at 1:29:35 PM UTC-4, Bonita Montero wrote:
> > the case in C and C++. Also, import is not the same as include.
 
> We shoud drop discussing doing "using" in an include-file since no one
> with a clear mind would do that.
 
Agreed, in my posts I have always assumed the context is .cpp files.
 
Daniel
"Öö Tiib" <ootiib@hot.ee>: Apr 28 11:13AM -0700

On Sunday, 28 April 2019 20:27:32 UTC+3, Bonita Montero wrote:
> > within one code file. In C++ however everything else gets
> > damaged by that include file from yet another noob coming from Java.
 
> No serious C++-developer would use using in a C++-header.
 
How so? Most C++ library classes in header are full of that.
Lets take a random container:
 
namespace project {
namespace module {
 
class container {
using value_type = blah;
using allocator_type = bla_blah;
using reference = bleh;
// etc. const_reference, iterator, const_iterator, size_type
// difference_type, pointer, const_pointer TL;DR;
 
// code starts only page later
};
}
}
 
Just peek into boost or something. For me that is fine when
container::value_type happens to be std::string. What feels like
nonsense is when container::string happens to be std::string.
WTF is container's string? That is brain damage squared and
does not make any sense.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 08:20PM +0200

> How so? Most C++ library classes in header are full of that.
 
I think you understood which type of using I meant.
Daniel <danielaparker@gmail.com>: Apr 28 11:30AM -0700

On Sunday, April 28, 2019 at 2:13:20 PM UTC-4, Öö Tiib wrote:
 
> How so?
 
I was assuming Bonita meant "using namespace"
 
Daniel
Paavo Helde <myfirstname@osa.pri.ee>: Apr 28 09:33PM +0300

On 27.04.2019 19:23, Bonita Montero wrote:
>> And where exactly are you going to search for its documentation, if you
>> don't even know if it's a custom function or a standard library function?
 
> I right-click at the symbol in my IDE and then click "go to definition".
 
In my IDE this works ... over half of the time. That's actually much
better than 10 years ago, when it almost never worked.
 
When it does not work, then the last version of the IDE has developed a
nasty habit to bring me to a wrong definition of the same symbol in a
totally unrelated project. Earlier versions at least did fail honestly.
 
Even if it worked reliably, it's more hassle for the reader than needed.
Why should I click, wait and verify that a symbol comes from std::?
Write it down, plain and simple!
"Öö Tiib" <ootiib@hot.ee>: Apr 28 11:41AM -0700

On Sunday, 28 April 2019 21:30:14 UTC+3, Daniel wrote:
> On Sunday, April 28, 2019 at 2:13:20 PM UTC-4, Öö Tiib wrote:
 
> > How so?
 
> I was assuming Bonita meant "using namespace"
 
Oh, using namespace I have learned to dislike everywhere.
"using x = y;" or "namespace bs = cattle::excrements;" are
fine but "using namespace std;" is just bad feature regardless
where.
Vir Campestris <vir.campestris@invalid.invalid>: Apr 28 09:44PM +0100

On 28/04/2019 16:51, Öö Tiib wrote:
> size_t or wchar_t has been source of some unexpected work over the
> years and so those are better to be used specially for performance
> optimization.
 
I boobed again. I should have said "same ABI".
 
Andy
Paavo Helde <myfirstname@osa.pri.ee>: Apr 28 09:44PM +0300

On 28.04.2019 20:28, Juha Nieminen wrote:
 
> std::shared_ptr *itself*, however, is not thread-safe.
 
> This confuses me a bit. Exactly which member functions are safe to be
> called from threads and in which situations?
 
The potentially unsafe methods are the ones which change the pointer
value, i.e. assignment, swap, etc.
 
> visible to all threads. Am I correct to assume that doing this in
> two different threads is safe?
 
> std::shared_ptr<Type> localPtr = commonPtr;
 
This line is safe as localPtr is either an automatic variable which is
not visible to other threads, or a namespace-level static whose
initialization is single-threaded.
 
> while doing this is not:
 
> commonPtr = localPtr;
 
Correct, if commonPtr is visible to multiple threads you will need some
kind of locking here.
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.