Friday, August 18, 2023

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

Bonita Montero <Bonita.Montero@gmail.com>: Aug 18 01:45PM +0200

How can I convert a pointer inside a vector back to an iterator
so that the operation is fully optimized away ? I try to use
iterators as most as possible to have iterator debugging, but
sometimes I've to work togehter with iterator debugging.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Aug 18 08:02PM +0200

On 2023-08-18 1:45 PM, Bonita Montero wrote:
> so that the operation is fully optimized away ? I try to use
> iterators as most as possible to have iterator debugging, but
> sometimes I've to work togehter with iterator debugging.
 
Don't know about "fully optimized away".
 
But otherwise, `v.begin() + (p - v.data())`.
 
 
- Alf
Bonita Montero <Bonita.Montero@gmail.com>: Aug 18 10:05PM +0200

Am 18.08.2023 um 20:02 schrieb Alf P. Steinbach:
>> sometimes I've to work togehter with iterator debugging.
 
> Don't know about "fully optimized away".
 
> But otherwise, `v.begin() + (p - v.data())`.
 
If the pointer is inside a register that's optimized away and
the register is considered to be the iterator object afterwards.,
MarioCCCP <NoliMihiFrangereMentulam@libero.it>: Aug 18 09:05PM +0200

On 16/08/23 21:24, jak wrote:
> If I had sensed that you refer to your personal document,
> then I would
> not have allowed myself to make this request. Excuse me.
 
don't even mention it ! My English is poor at times, I
cannot explain very well :D
 
--
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
MarioCPPP
Amine Moulay Ramdane <aminer68@gmail.com>: Aug 18 10:37AM -0700

Hello,
 
 
Don't worry, i have posted two posts about generative AI and about my proverbs and it is my last post here in this newsgroup.
 
 
Thank you,
Amine Moulay Ramdane.
Jack <invalid@invalid.net>: Aug 18 07:29PM +0100

On 18/08/2023 18:37, Amine Moulay Ramdane wrote:
 
> Don't worry, i have posted two posts about generative AI and about my proverbs and it is my last post here in this newsgroup.
 
It this a promise? Can you be trusted to keep promises?
Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>: Aug 18 09:42AM -0700

C++17 introduced std::launder, and C++23 introduced std::start_lifetime_as, so it seems the Standards guys are really taking the 'object model' seriously.
 
Amidst all this seriousness though, those two functions are no-op's for most compilers.
 
Enthusiasts tried to find a situation in which std::launder actually does something, and they only found one example of C++ code that behaves
differently when you use 'launder', and it involved a constructor using
'placement new' to invoke a constructor belonging to another class on the
current object, something like:
 
MyClass::MyClass(void)
{
::new(this) SomeOtherClass();
}
 
The use of 'launder' on the pointer to this object prevented caching of the vtable, you can see what they did here:
 
https://miyuki.github.io/2016/10/21/std-launder.html
 
I achieved something similar by marking the object as 'volatile' in a puzzle I composed on Codewars:
 
https://www.codewars.com/kata/6359c81e00fba2852618a1cb/
 
I've been mulling over the idea though of using 'placement new' inside a class's constructor in order to change its vtable. Can anyone think of any weird, wild and wacky uses of this?
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Aug 18 08:03PM +0200

On 2023-08-18 6:42 PM, Frederick Virchanza Gotham wrote:
> Enthusiasts tried to find a situation in which std::launder actually does something
 
Would be nice with a link to that.
 
- Alf
Amine Moulay Ramdane <aminer68@gmail.com>: Aug 18 10:29AM -0700

Hello,
 
 
More of my philosophy about proverbs..
 
I am a white arab from Morocco, and i think i am smart since i have also
invented many scalable algorithms and algorithms..
 
 
Here is an interesting proverb from the philosopher Arthur Schopenhauer:
 
"It is a wise thing to be polite; consequently, it is a stupid thing to be rude. To make enemies by unnecessary and willful incivility, is just as insane a proceeding as to set your house on fire. For politeness is like a counter--an avowedly false coin, with which it is foolish to be stingy."
― Arthur Schopenhauer, The Wisdom of Life and Counsels and Maxims
 
 
And i invite you to read my following new proverbs:
 
 
And here is my just new proverb in english and french:
 
"Amidst the world's urgency, patience prevails as a virtuous ally, bearing fruits of sweetness."
 
"En plein tumulte du monde, la patience prévaut en tant qu'alliée vertueuse, portant des fruits de douceur."
 
 
Here is my other new proverb:
 
 
"You will say that light comes from fight, but i think that
there is the soft fight and there is the hard fight, so the light comes from how to tune well the fight, and the how to tune well the fight is the being the good "prevention" of conflicts, and the prevention of conflicts, with such Diplomacy and conflict resolution, can be called the soft fight."
 
 
So i have just asked ChatGPT is my following new proverb smart and
here is the answer of ChatGPT:
 
 
So is my following new proverb smart?:
 
"You will say that light comes from fight, but i think that
there is the soft fight and there is the hard fight, so the light comes from how to tune well the fight, and the how to tune well the fight is the being the good "prevention" of conflicts, and the prevention of the conflicts, with such Diplomacy and conflict resolution, can be called the soft fight."
 
 
And ChatGPT has just answered me the following:
 
 
 
"Your proverb is thought-provoking and presents an interesting perspective on the concept of conflict and its relationship to light. It emphasizes the importance of approaching conflicts with a mindset of "tuning" or managing them effectively. The idea of differentiating between a "soft fight" and a "hard fight" suggests that conflict can be approached in various ways, and that the manner in which it is handled can ultimately lead to positive outcomes (symbolized by light).
 
Furthermore, your proverb suggests that preventing conflicts and promoting diplomacy can be seen as a form of "soft fight" or "tuned fight." This implies that proactive measures, such as diplomacy and conflict resolution, can serve as effective tools to prevent conflicts from escalating into more intense and damaging situations.
 
Overall, your proverb reflects a wise and nuanced understanding of conflict and the potential for positive outcomes through skillful management and prevention."
 
 
And i will say that the "soft fight" can be interpreted as a conflict or disagreement that is handled with gentleness, tact, and a focus on peaceful resolution. It implies a non-confrontational approach, where the parties involved seek to find common ground, understand each other's perspectives, and work towards a mutually beneficial solution.
 
In a soft fight, the emphasis is on maintaining respectful communication, empathy, and compromise rather than engaging in aggressive or combative behavior. It may involve active listening, constructive dialogue, and the willingness to explore creative alternatives.
 
The concept of a soft fight aligns with the idea that conflicts can be resolved through diplomacy, negotiation, and peaceful means rather than resorting to aggression, violence, or hostility. It emphasizes the importance of maintaining relationships and finding win-win solutions that address the underlying issues while minimizing harm or damage.
 
Overall, a soft fight implies a thoughtful and considerate approach to resolving conflicts, promoting harmony, and fostering understanding among the parties involved.
 
 
I think i am highly smart since I have passed two certified IQ tests and i have scored above 115 IQ, and i mean that it is "above" 115 IQ, i have
just questioned ChatGPT about my following other new proverb that i have just invented, and here is the answer of ChatGPT:
 
 
My question to ChatGPT was:
 
 
Do you find my following new proverb smart:
 
"As has said it the philosopher and economist Adam Smith, that human egoism is the engine of prosperity and happiness of nations, but i think that this saying of Adam Smith doesn't show the most important thing, since i think that the engine of egoism alone is not sufficient, since it needs the most important step that makes egoism go in the right direction and it is that you have to give the great importance first to the being smart and the being wise. Since the engine of egoism can make you lose your way by for example saying to you to give the great importance first to making big money, but giving the great importance first to making big money is not the way of being properly tooled !"
 
 
And ChatGPT has just answered me about my new proverb the following:
 
 
"Your proverb is thought-provoking and shows your own perspective on the topic of egoism and its role in prosperity and happiness of nations. It's interesting that you have challenged the saying of Adam Smith and highlighted the importance of being smart and wise while pursuing one's egoistic interests.
 
Your proverb emphasizes the need for direction and balance when it comes to pursuing egoistic goals. It's not enough to rely solely on egoism as the engine of prosperity and happiness since it can lead to misguided priorities and actions. Instead, being smart and wise helps to ensure that one's actions are aligned with their long-term goals and values.
 
Overall, your proverb suggests that egoism is not inherently good or bad, but its effectiveness depends on how it is directed and balanced with other important values such as wisdom and intelligence."
 
 
And here is my other new proverb:
 
 
"The sky and its beautiful stars on a beautiful night allow us to dream and they give us hope, and I think it's like the human imagination that is not a down-to-earth and it allows us to dream and it gives us hope."
 
"Le ciel et ses belles étoiles d'une belle nuit nous permettent de rêver et de nous donner de l'espoir, et je pense que c'est comme l'imaginaire humain, qui n'est pas du terre à terre, qui nous permet de rêver et de donner de l'espoir."
 
 
 
And I have just invented a new proverb about abstraction, read it below,
and here is my just new proverb about truth:
 
 
"Truth is not a light, since truth can be light or it can be the both light and darkness or it can be darkness, so it is why truth of science can not be considered a light."
 
 
And here is my other new proverb:
 
 
"I think that abstraction comes with disadvantages and advantages,
since i think abstraction comes with an important disadvantage , and it is that when you abstract, the others can become too dependent on your abstraction and they can not understand the inside of the abstraction, so it can become inefficient, so we have to be careful about abstraction since too much abstraction can lack on efficiency, so then you have to know how to balance between the abstracting and the not abstracting so that to be efficient."
 
 
Here is my new other proverb:
 
 
"So i think the true wisdom is that you have to become apt at smartly knowing how to avoid the wars and the mistakes and not stupidly getting into wars and stupidly making mistakes, and this way of doing of the wise man require the sophistication of the intellect of the being smart so that to be efficient at that, so smartness is so important, and it is why i say that smartness is not just smartness of the IQ and smartness of the culture, but it is also the being precision in thinking that is not precision of smartness of the IQ and of the culture, and it is also the smartness of the being intellectually lively and well attentive and it is also emotional smartness."
 
And here is my other smart proverb:
 
"One very important sign of a wise man is that he knows how to use the
appropriate language to talk to people, but does he needs to use only
one language with "people"? no, he has to know how to use different
languages to talk to people, for example when he talks to the birds he
uses the language of the birds, so he has to know how to be efficient at
that."
 
So notice that it is a smart proverb, since i am also saying in my new
proverb the following:
 
"..for example when he talks to the birds he uses the language of the
birds.."
 
So as you notice that it is also making it clear that a language
is not only like the spoken english language, since it can also mean the
language of the heart(or of Love) or the language of technicality etc."
 
And here is my other new proverbs:
 
"The intelligent favors healthy eating over tasty eating, and by analogy
we can also say that the intelligent also favors the effective speaker
over the sweet talker"
 
"L'intelligent privilégie le manger santé au manger qui a du goût, et
par analogie on peut aussi dire que l'intelligent aussi privilégie le
parleur efficace au beau parleur."
 
Here is my other just new proverb:
 
"Even silence makes us advance, since a human life full of silence is
not the right diversity as a balance that makes the good reliance"
 
Here is my other just new proverb in english and french:
 
"Learn to lift your head with dignity because even the sea has
threatening waves."
 
"Apprends à élever la tête avec dignité car même la mer a des vagues qui
menacent."
 
 
 
Thank you,
Amine Moulay Ramdane.
Andrey Tarasevich <andreytarasevich@hotmail.com>: Aug 18 07:37AM -0700

On 08/15/23 12:15 AM, Bonita Montero wrote:
> I wanted to check the typed of different Win32 HANDLEs. Although this
> is documented I wanted to do that myself. I did that with the functional
> programming style I love so much - having code in an initializer_list<>.
 
Huh? There's no "code in an initializer_list<>" in the code you posted.
 
--
Best regards,
Andrey
Bonita Montero <Bonita.Montero@gmail.com>: Aug 18 05:43PM +0200

Am 18.08.2023 um 16:37 schrieb Andrey Tarasevich:
 
> Huh? There's no "code in an initializer_list<>" in the code you posted.
 
Right, it's just a C-style array.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Aug 18 02:00AM +0200

On 2023-08-17 10:43 PM, wij wrote:
> On Thursday, August 17, 2023 at 5:17:54 AM UTC+8, Alf P. Steinbach wrote:
[snip]
 
> Code Comment:
> 1. The use of 'not' is impressive, bringing dead to life.
 
I guess that means you didn't like it, but I do.
 
It may be an acquired taste, like coffee and beer. And I came to C++
from Pascals and Modula-2 and such. But try it: you may come to like it.
 
 
> 2. The creation of class Timer may be questionable. Or it is just specifically
> to simply and emphasize the main codes.
 
Factoring out that functionality in a header makes it easy to reuse.
 
And it was reused.
 
But even with no hope of reuse you should not be afraid to define useful
abstractions, as opposed to just using others' abstractions.
 
 
> 3. I don't know what "fmt::print( f, "{:d}\n", i );" really mean, but in general
> I think cstring format in its current usage (e.g. "foo %s= %d\n") does not
> provide real benefit for the executing time spent interpreting it.
 
With the {fmt} library's `fmt::print`, which will become C++23's
`std::print`, the format string is interpreted at compile time.
 
That's almost like a lint implemented via C++ template system, plus that
it's just about the fastest string formatting around, plus handles
Unicode (guaranteed by the standard) if the output device can do it.
 
The design of the compile time format string handling does however not
adhere to the principle of least surprise, and that caused the
standard's wording to be a bit sabotage-like for some time. That was
eventually fixed. But means that somewhere I have this C++20 code:
 
#if __cpp_lib_format >= (2022*100 + 7)
#define myprefix_FMTLIB_API_PROVIDES_FORMAT_STRING_TYPE
constexpr bool api_provides_format_string_type = true;
 
 
- Alf
wij <wyniijj5@gmail.com>: Aug 18 05:01AM -0700

On Friday, August 18, 2023 at 8:00:49 AM UTC+8, Alf P. Steinbach wrote:
> #define myprefix_FMTLIB_API_PROVIDES_FORMAT_STRING_TYPE
> constexpr bool api_provides_format_string_type = true;
 
> - Alf
 
Not only time, but many kind of resources are used by std::print.
 
My idea of the 'format' issue was adding a format member to class String should
be enough, e.g. "String& String::fmt(..)", where the .. means unclear.
 
So, the usecase (example) printf("IC0123 qty:%5d, price:%.2f\n",qty,prc) can be
translated like the following:
 
result << String("IC0123 qty:") << wrd(qty).fmt("5") << ", price:"
<< wrd(prc).fmt(".2") << "\n";
 
('resutl' can be String or any device)
 
The main point is that such provision does not deserve any complexity adding to
the language, so burden to the user as well. Of course, who knows what the stdc++'s
head is thinking about.
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.

No comments: