Friday, April 28, 2023

Digest for comp.lang.c++@googlegroups.com - 19 updates in 1 topic

Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 03:35AM +0200

Am 27.04.2023 um 20:18 schrieb Scott Lurndal:
 
> Indeed, in the real world one attempts to make the code readable
> to all colleagues (and for open source, the whole world), regardless
> of each colleagues skill level.
 
My code is easy to read if you know C++20 concepts.
"Öö Tiib" <ootiib@hot.ee>: Apr 27 09:58PM -0700

On Friday, 28 April 2023 at 04:36:15 UTC+3, Bonita Montero wrote:
> > to all colleagues (and for open source, the whole world), regardless
> > of each colleagues skill level.
> My code is easy to read if you know C++20 concepts.
 
I you are such a rockstar programmer then perhaps provide cite of that
opinion.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 07:17AM +0200

Am 28.04.2023 um 06:58 schrieb Öö Tiib:
 
 
> I you are such a rockstar programmer then perhaps provide cite of that
> opinion.
 
I use concepts how they're meant, i.e. constraining all generic
types in a way that the code gets meaningful errors if the caller's
type don't match that constraints.
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Apr 28 01:47AM -0700

On Friday, 28 April 2023 at 05:58:36 UTC+1, Öö Tiib wrote:
> > My code is easy to read if you know C++20 concepts.
> I you are such a rockstar programmer then perhaps provide cite of that
> opinion.
 
It's a general problem with modern C++. Unless you are very familiar with
the language, code is hard to read, because it's not similar to other
languages. However you can argue that that is the case for C++ - there's
not much point in a language which just has a slightly different syntax for
counted loops but is otherwise essentially C.
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Apr 28 01:55AM -0700

On Friday, 28 April 2023 at 05:58:36 UTC+1, Öö Tiib wrote:
> > My code is easy to read if you know C++20 concepts.
> I you are such a rockstar programmer then perhaps provide cite of that
> opinion.
Bonita's prototype
template<std::input_iterator InputIt, typename IsEnd, typename Consumer>
requires std::is_integral_v<std::iter_value_t<InputIt>>
&& requires( IsEnd isEnd, InputIt it ) { { isEnd( it ) } ->
std::convertible_to<bool>; }
&& requires( Consumer consumer, InputIt inputIt ) { { consumer(
inputIt, inputIt ) }; }
 
We've got three templated type, InputIt, isEnd, and Consumer.
 
InputIt must be an input iterator.
 
The we've got the constriants.
InputIt must have an integral value type
isEnd must be a callable type which returns a boolean compatible type whe called with an InputIt
Consumer must be a callable typewhich takes two InputIts.
 
It's not too hard.
Muttley@dastardlyhq.com: Apr 28 09:01AM

On Thu, 27 Apr 2023 18:21:09 +0200
>and g++ you now get descriptive errors which show which constraint is
>violated. You don't even have to understand how to write concepts to
>understand the resulting errors.
 
So you're saying that a new construct needs to be added to the language in
order to allow sane compile errors? Riiiiight...
 
 
>Idiot.
 
>> Your psychological analysis is as bad as your code.
 
>I'm right on that because you're overburdened with a lot of new things.
 
No, I'm just able to filter out the crap.
Muttley@dastardlyhq.com: Apr 28 09:03AM

On Thu, 27 Apr 2023 13:15:50 -0700
 
>Bonita is an interesting person. Seemingly "loves" to insult, but....
>Bonita is anything but stupid. One time I loosely compared her to the
>cruel puppet:
 
Oh he's (and its almost certainly a man) not stupid. Just has no understanding
of other people and likes to show off.
Muttley@dastardlyhq.com: Apr 28 09:13AM

On Thu, 27 Apr 2023 18:50:30 +0200
>> software development.
 
>I'm 51 and I'm programming since I'm 10 and I'm skilled far
>beyond you. What impression do you think you make on others,
 
You think you're skilled because you can play around with various language
constructs. Software development involves writing code that actually does
something useful beyond some demonstation snippet. What have you done?
 
>except for those who are not better at programming than you ?
 
You're like the amateur guitar player who can play a few riffs from [some band]
really well to impress people at a party. But put him on on a stage and ask him
to do an entire concert and he'd fall apart.
Muttley@dastardlyhq.com: Apr 28 09:14AM

On Thu, 27 Apr 2023 11:45:01 -0700 (PDT)
>code as particularly readable? =20
 
>https://github.com/martinus/robin-hood-hashing/blob/master/src/include/robi=
>n_hood.h
 
Templates mixed up with macros. Ugh.
Muttley@dastardlyhq.com: Apr 28 09:15AM

On Fri, 28 Apr 2023 01:55:18 -0700 (PDT)
>alled with an InputIt
>Consumer must be a callable typewhich takes two InputIts.
 
>It's not too hard.
 
You think having to spend time figuring out metacode in a function prototype
is acceptable?
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 11:16AM +0200

I straightened the code a bit:
 
#pragma once
#include <type_traits>
#include <iterator>
#include <concepts>
 
template<typename Iterator, typename Consumer>
concept linify_input_iterator =
std::input_iterator<Iterator>
&& requires( Iterator inputIt ) { { *inputIt == char() } ->
std::convertible_to<bool>; }
&& requires( Consumer consumer, Iterator inputIt ) { { consumer(
inputIt, inputIt ) }; };
 
template<typename Iterator, typename IsEnd, typename Consumer>
requires linify_input_iterator<Iterator, Consumer>
&& requires( IsEnd isEnd, Iterator it ) { { isEnd( it ) } ->
std::convertible_to<bool>; }
void linify( Iterator begin, IsEnd isEnd, Consumer consumer )
{
using namespace std;
if( isEnd( begin ) ) [[unlikely]]
return;
for( Iterator scn = begin; ; )
for( Iterator lineBegin = scn; ; )
if( *scn == '\n' ) [[unlikely]]
{
consumer( lineBegin, scn );
if( isEnd( ++scn ) )
return;
break;
}
else if( *scn == '\r' ) [[unlikely]]
{
consumer( lineBegin, scn );
if( isEnd( ++scn ) || *scn == '\n' && isEnd( ++scn ) )
return;
break;
}
else if( isEnd( ++scn ) ) [[unlikely]]
{
consumer( lineBegin, scn );
return;
}
}
 
template<typename Iterator, typename Consumer>
requires linify_input_iterator<Iterator, Consumer>
inline void linify( Iterator begin, Iterator end, Consumer consumer )
{
linify( begin, [&]( Iterator it ) -> bool { return it == end; },
consumer );
}
 
template<typename Iterator, typename Consumer>
requires linify_input_iterator<Iterator, Consumer>
inline void linify( Iterator begin, Consumer consumer )
{
linify( begin, [&]( Iterator it ) -> bool { return !*it; }, consumer );
}
 
 
The common parts of all three functions are now in a concept,
the individual parts of the first function are still there.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 11:17AM +0200


> You think having to spend time figuring out metacode in a function prototype
> is acceptable?
 
This makes the code more readable and usable since you directly see
what are the required constraints on the generic types and if you
supply variables that don't have these properties you get more mea-
ningful errors.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 11:18AM +0200


> So you're saying that a new construct needs to be added to the language in
> order to allow sane compile errors? Riiiiight...
 
Generic code may lead to errors from inside the functions.
So you have a more meaningful error from outside the function
and you won't have to deal with the details.
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Apr 28 02:49AM -0700

> >understand the resulting errors.
 
> So you're saying that a new construct needs to be added to the language in
> order to allow sane compile errors? Riiiiight...
 
It's because of the way that templates developed in C++ from what was originally
a very limited idea to a sophisticated system. The syntax will accept any type.
However the surrounding code can only rarely accept any type whatsoever.
Worse, you can sometimes have subtle bugs, for example when passing an
integral type to a function which needs to do real arithmetic. The compiler is
of course incapable of understanding this.
Muttley@dastardlyhq.com: Apr 28 10:25AM

On Fri, 28 Apr 2023 02:49:10 -0700 (PDT)
>Worse, you can sometimes have subtle bugs, for example when passing an
>integral type to a function which needs to do real arithmetic. The compiler is
>of course incapable of understanding this.
 
Thats why template specialisation was created.
Muttley@dastardlyhq.com: Apr 28 10:27AM

On Fri, 28 Apr 2023 11:18:55 +0200
 
>Generic code may lead to errors from inside the functions.
>So you have a more meaningful error from outside the function
>and you won't have to deal with the details.
 
Compiler writers are quite capable of making their compilers give useful
errors. Clang is a lot better at it than gcc for example , the latter whom
often dumps pages of borderline unparsable garbage to the screen. Thats not
a problem with C++, its a problem with gcc.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 12:57PM +0200


> Compiler writers are quite capable of making their compilers give useful
> errors. ...
 
Do you ever have debugged generic function-objects inside generic code
like you use ? The errors are much less useful than coming from a con-
cept. And you even don't have to understand concepts but just the error.
 
> Clang is a lot better at it than gcc for example, ...
 
You don't know what you're talking about. Imagine I wouldn't have con-
cepted my code and the isEnd Function-Object doesn't return a bool or
the consumer function-object doesn't accept two of the given forward
-iterators. The errors are more complicated to read than those resul-
ting from a concept. And if you have code like of common runtimes it
looks at Swahili to inspect that; then I'd rather perfer clean concepts.
Muttley@dastardlyhq.com: Apr 28 11:04AM

On Fri, 28 Apr 2023 12:57:41 +0200
>cept. And you even don't have to understand concepts but just the error.
 
>> Clang is a lot better at it than gcc for example, ...
 
>You don't know what you're talking about. Imagine I wouldn't have con-
 
You're an arrogant ass sometimes. Every piece of personal code I write I compile
on MacOS and Linux (clang and gcc) and clang is far better at error reporting
than gcc in generic code but there's still plenty of room for improvement.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 02:11PM +0200


> You're an arrogant ass sometimes. Every piece of personal code I write I compile
> on MacOS and Linux (clang and gcc) and clang is far better at error reporting
> than gcc in generic code but there's still plenty of room for improvement.
 
The errors of any compiler when supplying types that don't match the
criteria are a lot harder to read than when the compiler says you which
properties are missing according to the concept - with any compiler.
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.

Wednesday, April 26, 2023

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

Lynn McGuire <lynnmcguire5@gmail.com>: Apr 26 04:43PM -0500

"C++: Windows Toast Notification" by Shao Voon Wong

https://www.codeproject.com/Articles/5286393/Cplusplus-Windows-Toast-Notification
 
 
"Windows Toast is a small window appearing at the bottom-right of the
screen, is a common method whereby an application notifies its user an
event of interest has occurred, for instance, a video encoding session
has completed. Compared to MesssageBox() which shows a child modal
window of your application is like a shove in your user's face
especially when your application is currently not in the foreground. In
this regard, Windows Toast is less intrusive. But to understand and use
its complex API correctly is not an easy task."
 
Lynn
Bonita Montero <Bonita.Montero@gmail.com>: Apr 26 07:11AM +0200

Am 25.04.2023 um 17:56 schrieb Richard:
> entered string for which std::string is sufficient.
 
> I'm not aware of any such library, but I thought I'd ping out to see
> if anything rings a bell.
 
I have something related to this topic. And reading in several lines
one line at a time is quite slow with the implementations of the C++
standard library. So I came up with the idea of writing a function
that I called linify() that has a generic callback that takes the
lines as a pair of start and end iterators. Here is the code:
 
#pragma once
#include <type_traits>
#include <iterator>
 
template<std::input_iterator InputIt, typename IsEnd, typename Consumer>
requires std::is_integral_v<std::iter_value_t<InputIt>>
&& requires( IsEnd isEnd, InputIt it ) { { isEnd( it ) } ->
std::convertible_to<bool>; }
&& requires( Consumer consumer, InputIt inputIt ) { { consumer(
inputIt, inputIt ) }; }
void linify( InputIt begin, IsEnd isEnd, Consumer consumer )
{
using namespace std;
if( isEnd( begin ) ) [[unlikely]]
return;
for( InputIt scn = begin; ; )
for( InputIt lineBegin = scn; ; )
if( *scn == '\n' ) [[unlikely]]
{
consumer( lineBegin, scn );
if( isEnd( ++scn ) )
return;
break;
}
else if( *scn == '\r' ) [[unlikely]]
{
consumer( lineBegin, scn );
if( isEnd( ++scn ) || *scn == '\n' && isEnd( ++scn ) )
return;
break;
}
else if( isEnd( ++scn ) ) [[unlikely]]
{
consumer( lineBegin, scn );
return;
}
}
 
template<std::input_iterator InputIt, typename Consumer>
requires std::is_integral_v<std::iter_value_t<InputIt>>
&& requires( Consumer consumer, InputIt inputIt ) { { consumer(
inputIt, inputIt ) }; }
inline void linify( InputIt begin, InputIt end, Consumer consumer )
{
linify( begin, [&]( InputIt it ) -> bool { return it == end; }, consumer );
}
 
template<std::input_iterator InputIt, typename Consumer>
requires std::is_integral_v<std::iter_value_t<InputIt>>
&& requires( Consumer consumer, InputIt inputIt ) { { consumer(
inputIt, inputIt ) }; }
inline void linify( InputIt begin, Consumer consumer )
{
linify( begin, [&]( InputIt it ) -> bool { return !*it; }, consumer );
}
 
 
Since the lambda of the consumer exists only once globally for the
entire application and has its own unique type, which means that
the instantiation of linify() also only exists once, the linify()
function and the lambda are compiled to where it is called .
legalize+jeeves@mail.xmission.com (Richard): Apr 26 06:22AM

[Please do not mail me a copy of your followup]
 
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> spake the secret code
 
>[asked a ton of questions but made no mention of any existing library]
 
Do you have a library in mind or are you trying to build one?
 
I can build one just fine for myself, but it's best to ask around to
see if one already exists.
--
"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>
Muttley@dastardlyhq.com: Apr 26 08:22AM

On Wed, 26 Apr 2023 07:11:47 +0200
> && requires( Consumer consumer, InputIt inputIt ) { { consumer(
>inputIt, inputIt ) }; }
>void linify( InputIt begin, IsEnd isEnd, Consumer consumer )
 
Serious question - do you really think this is a sane function prototype or
anything approaching intelligable code?
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Apr 26 04:11AM -0700

On Tuesday, 25 April 2023 at 16:57:15 UTC+1, Richard wrote:
> entered string for which std::string is sufficient.
 
> I'm not aware of any such library, but I thought I'd ping out to see
> if anything rings a bell.
 
It depends how you are processing these strings, and whether you need to do
it in just noticeable time on a personal computer, or as fast as possible on
a server.
If you are doing very many searches on a fixed body of text, then the structure to
use is a suffix tree. It's about ten times as memory intensive as a flat string,
but it allows for searching in constant time. However a suffix tree isn't easy to
implement, and is overkill for most text processing.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 26 08:03PM +0200

>> void linify( InputIt begin, IsEnd isEnd, Consumer consumer )
 
> Serious question - do you really think this is a sane function prototype or
> anything approaching intelligable code?
 
This prototype makes that the iterator and the consumer function
objects have the required properties through C++20 conceots. This
prevents any errors from inside the function body, which makes the
code easier to handle for people using the code.
If you don't like concepts you could delete them. But don't wonder
if you have typical template type property errors from inside the
function.
I think concepts are easy to read.
"Öö Tiib" <ootiib@hot.ee>: Apr 25 10:58PM -0700

On Tuesday, 25 April 2023 at 23:32:28 UTC+3, Chris M. Thomasson wrote:
 
> I was not really mocking the "style", just how some programmers do not
> like it at all... Personally, I don't mind it. Each function has a
> struct for input and a struct for output.
 
OK. I do not hate it but I feel it has same issue with returning std::optional
or std::expected, there is additional copy (or hopefully move) made for
composing such function arguments and return value and so it inhibits the
effect (or works in the opposite direction) of NRVO. Especially on
case of heavy-weight "success" objects passed the performance can
drop after refactoring to it. And performance issue means that the
style can not be used idiomatically/uniformly.
David Brown <david.brown@hesbynett.no>: Apr 26 09:26AM +0200

On 26/04/2023 07:58, Öö Tiib wrote:
> case of heavy-weight "success" objects passed the performance can
> drop after refactoring to it. And performance issue means that the
> style can not be used idiomatically/uniformly.
 
In regard to performance issues, you might want to do some testing and
measuring. Small structures on modern processors can be passed and
returned in registers in many cases. The use of structs for parameters
and return values might limit the compiler's choice of registers and
force a bit more register-to-register moves, but these are often almost
free in modern processors since they manipulate the register renaming
maps rather than actually moving data around.
 
Whether or not you like Chris' style or not is a different matter, of
course - I'm just saying that it will not necessarily have the
performance implications you suggest.
"Öö Tiib" <ootiib@hot.ee>: Apr 26 03:57AM -0700

On Wednesday, 26 April 2023 at 10:26:53 UTC+3, David Brown wrote:
> > style can not be used idiomatically/uniformly.
 
> In regard to performance issues, you might want to do some testing and
> measuring.
 
What is the ground of implication that I do not? You think those are my
half-educated guesses? Nope. Those are actually reverted commits because
of proven degradation of performance.
 
> force a bit more register-to-register moves, but these are often almost
> free in modern processors since they manipulate the register renaming
> maps rather than actually moving data around.
 
Note that I mentioned heavy-weight above.
 
> Whether or not you like Chris' style or not is a different matter, of
> course - I'm just saying that it will not necessarily have the
> performance implications you suggest.
 
It sometimes has and sometimes does not have. I'm repeating for
to point arrive more surely, it cannot be used idiomatically/uniformly.
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.

Sunday, April 23, 2023

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

Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>: Apr 23 01:51PM -0700

The problem with arbitrarily pushing data onto the stack for it to be retrieved by some other function later on down the chain of function calls, is that each function in the chain of function calls may increment and decrement the stack pointer here and there, and so we won't know what offset to apply to the stack pointer in order to retrieve our data.
 
They say that if you generate a 128-Bit random number, then it's a one of a kind and you don't have to worry about it ever being duplicated. So let's generate our own UUID:
 
#define UUID "\x24\x31\x07\x26\x35\x2c\x4f\x9a\x99\x65\xe1\x10\x65\x62\x92\xcc"
 
So if we push this UUID onto the stack, and then place our data right beside it on the stack, then later on we can search the stack for this UUID and we'll find our data right beside it.
 
Now at first I was going to write x86_64 assembler to push an arbitrary number of bytes onto the stack, but that would malfunction if the compiler didn't use the frame pointer perfectly, which I don't think you're even guaranteed if you supply '-fno-omit-frame-pointer'. Luckily though, some compilers have a built-in function called 'alloca' which you can read about here:
 
https://man7.org/linux/man-pages/man3/alloca.3.html
 
So I'll use the function "__builtin_alloca" to decrement the stack pointer, I'll copy the UUID onto the stack along with my data, and then later on I can search for my UUID on the stack in order to retrieve the data which will be located right beside it.
 
I got this working, here it is up on GodBolt:
 
https://godbolt.org/z/ofYPc74Gc
 
A week ago I shared some code here on comp.lang.c++ for how to write a thunk in machine code onto the stack and then execute the stack. Well, using the technique described in this post, we could instead look for the addresses of lambda objects on the stack without having to execute the stack. I'll write a new thunk generator tomorrow that uses this technique.
 
Here's the contents of GodBolt copy-pasted:
 
#include <cstddef> // size_t
#include <cstring> // memcpy
 
// The unique 128-Bit value we'll use to find our data on the stack
#define UUID "\x24\x31\x07\x26\x35\x2c\x4f\x9a\x99\x65\xe1\x10\x65\x62\x92\xcc"
 
extern "C" char *stack_pointer(void); // get the current value of the stack pointer
 
// The following is an x86_64 assembler implementation
// of a function to retrieve the current stack pointer
__asm("stack_pointer: \n mov %rsp,%rax \n ret");
 
// The following function pushes any amount of bytes of data
// onto the stack. It's implemented as a macro instead of a
// real function because of the use of '__builtin_alloca'.
// I have appended '_x8975w' to the name of every local variable
// so that we don't get a name clash with the caller.
#define push_onto_stack(arg_src,arg_count) \
do \
{ \
using std::size_t; \
char const *const src_x8975w = (arg_src); \
size_t const count_x8975w = (arg_count); \
char *dst_x8975w = static_cast<char*>( \
__builtin_alloca(count_x8975w + 16u + sizeof(size_t))); \
std::memcpy(dst_x8975w, UUID, 16u); \
dst_x8975w += 16u; \
std::memcpy(dst_x8975w, &count_x8975w, sizeof count_x8975w); \
dst_x8975w += sizeof count_x8975w; \
std::memcpy(dst_x8975w, src_x8975w, count_x8975w); \
} while (false);
 
char *retrieve_from_stack(std::size_t *const p = nullptr) __attribute__((no_sanitize_address));
char *retrieve_from_stack(std::size_t *const p) // amount of bytes retrieved goes in *p
{
char *sp = stack_pointer();
 
// Instead of simply using 'memcmp' which will
// be intercepted by '-fsanitize' to flag a
// stack-buffer-underflow, I have written a loop
Loop:
{
while ( UUID[0] != *sp++ ) /* Do Nothing */; // ++sp because stack grows down on x86
 
for ( unsigned i = 1u; i < 16u; ++i, ++sp )
{
if ( UUID[i] != *sp ) goto Loop;
}
}
 
// If control reaches here, we found the UUID on the stack
// Note: alignment for size_t is guaranteed by __builtin_alloca
if ( nullptr != p ) *p = *static_cast<size_t const*>(static_cast<void const*>(sp));
sp += sizeof *p;
return sp;
}
 
#include <iostream>
using std::cout, std::endl;
 
void Func3(void)
{
cout << "Hello from Func3\n";
size_t n;
cout << "Retrieved data = '" << retrieve_from_stack(&n) << "', count bytes = " << n << endl;
}
 
void Func2(void)
{
cout << "Hello from Func2\n";
Func3();
}
 
void Func(void)
{
cout << "Hello from Func\n";
Func2();
}
 
int main(void)
{
push_onto_stack("Monkeys eat bananas", sizeof "Monkeys eat bananas");
Func();
}
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <fqudbg5da2dgv4nm26nni1jjfjg29ffuks@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <0g5fbglkgur7er41qgvbto72d31ssm8siv@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <kh5ebg9difm5a9rp3btvk85c2oe60qtn6o@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <uiafbgt38f1fnhev1h2prvjuq01jhnt4qr@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <l43fbg92kfnb5o0ds0qrs9ealae23cbjs9@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <525fbg9ue4ice5h2930hmiff4l59lq3q7u@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <nvkebgp3pvkcmbet0auqe3clrjv4p8glcn@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <2r5fbg514knubm2mkr93p0qoq2119n91md@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <oktdbghqujenqb24g5h9rkk03peh375c55@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: Have you ever noticed ...
Message-ID: <qotdbg9mkvkhe0obbmsvtgpnglld4vp3ls@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <gmafbgdc2m1dca657tbo7t8ih62uie19vp@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <91gfbghrjhvjmllsss0ubsjps5b2fpi66v@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <72gfbgt14j6tcf9q4b4anquohldnlftnbb@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <3sfebg1q4a3nivpvk4qauuv9uqnpe4ug8j@4ax.com>
Newsgroups: comp.lang.c++
Doctor Who <doc@tardis.org>: Apr 23 08:57PM +0200

Post in violation of terms-of-service cancelled by Sir Cancelot <cancelbot@eternal-september.org>
From: Doctor Who <doc@tardis.org>
Subject: Re: lamda-optimization
Message-ID: <n1gfbg9etqs8fqfh582qivnd4rqvtchr4h@4ax.com>
Newsgroups: comp.lang.c++
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.

Saturday, April 22, 2023

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

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Apr 21 05:35PM -0700

Humm... It tried to tell me that cos(0) does not equal sin(pi/2)... This
is bad:
 
https://i.ibb.co/DgtknZS/image.png
 
Humm...
Manu Raju <MR@invalid.invalid>: Apr 22 03:56AM +0100

On 22/04/2023 01:35, Chris M. Thomasson wrote:
> This is bad:
 
> https://i.ibb.co/DgtknZS/image.png
 
> Humm...
 
Try this:
 
<https://i.imgur.com/6fDbiId.png>
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 11:09AM +0200

Am 22.04.2023 um 02:35 schrieb Chris M. Thomasson:
 
> is bad:
> https://i.ibb.co/DgtknZS/image.png
> Humm...
 
Depending on the implementation
bit_cast<int64_t>( sin( M_PI / 2 ) )
may be not equal to
bit_cast<int64_t>( cos( 0 ) ).
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Apr 22 12:45PM -0700

On 4/21/2023 7:56 PM, Manu Raju wrote:
 
>> Humm...
 
> Try this:
 
> <https://i.imgur.com/6fDbiId.png>
 
It learned! Nice. :^D
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Apr 22 12:50PM -0700

On 4/22/2023 2:09 AM, Bonita Montero wrote:
>     bit_cast<int64_t>( sin( M_PI / 2 ) )
> may be not equal to
>     bit_cast<int64_t>( cos( 0 ) ).
 
I was mostly interested in the mathematical truth that cos(0) =
sin(pi/2)... ;^)
 
Wrt degrees, pi/2 = 90 degrees.
 
So, I was not really interested in precision issues.
Andrey Tarasevich <andreytarasevich@hotmail.com>: Apr 22 11:20AM -0700

On 04/20/23 3:06 AM, Frederick Virchanza Gotham wrote:
> auto mylambda = [](void)->int { return 27u; };
 
> return *decltype(&mylambda)(nullptr);
> }
 
A lot of things became trivially "non-isolated" in C++ the moment the
language started to support `auto` return types and `decltype`
(primarily the former). Local types, `private` types... Yes, this is how
it is intended to work. Get used to it.
 
--
Best regards,
Andrey
Muttley@dastardlyhq.com: Apr 22 09:19AM

On Fri, 21 Apr 2023 19:31:30 +0200
 
>> I don't expect to have to spend a lot of my time googling obscure C++
>> semantics when working on code. ...
 
>Use a different language if you'd like to program like with C++98.
 
When you ever work in a corporate enviroment where code has to be clear and
maintainable by people of varying abilities then maybe you'll get a clue. In
the meantime enjoy life in your academic ivory tower.
Mr Flibble <flibble2@reddwarf.jmc.corp>: Apr 22 11:55AM +0100


> When you ever work in a corporate enviroment where code has to be clear and
> maintainable by people of varying abilities then maybe you'll get a clue. In
> the meantime enjoy life in your academic ivory tower.
 
std::optional is great and move semantics means returning by value need
not be more expensive than using an out parameter, there is RVO/NRVO
also; additionally, out parameters can be problematic for the optimiser.
 
/Flibble
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 01:17PM +0200


> When you ever work in a corporate enviroment where code has to be clear and
> maintainable by people of varying abilities then maybe you'll get a clue. ...
 
If you're relaxed and reasonably intelligent, you can learn
additional things on the side. My employer currently has two
vacancies that require C++17 and Boost. I think you're saying
the same thing about Boost that you're saying about more modern
C++ features: too complex and unnecessary.
Using modern language usually results in less code and sometimes
just more portable code.
Muttley@dastardlyhq.com: Apr 22 02:41PM

On Sat, 22 Apr 2023 11:55:54 +0100
>> the meantime enjoy life in your academic ivory tower.
 
>std::optional is great and move semantics means returning by value need
>not be more expensive than using an out parameter, there is RVO/NRVO
 
That depends on what you're doing. If you create a local object/array then
set up its values thats already more expensive that just updating a
reference without the create. Then you have to add the cost of doing the
move upon return. Despite what some people seem to think, move isn't costless.
 
>also; additionally, out parameters can be problematic for the optimiser.
 
Optimisers are a black box. The only way you can know which approach is faster
is try both.
Muttley@dastardlyhq.com: Apr 22 02:44PM

On Sat, 22 Apr 2023 13:17:51 +0200
>> maintainable by people of varying abilities then maybe you'll get a clue. ...
 
>If you're relaxed and reasonably intelligent, you can learn
>additional things on the side. My employer currently has two
 
Sure you can ,but if you have a deadline you really don't want to have to dig
into some obtuse syntax to figure out what its doing.
 
>vacancies that require C++17 and Boost. I think you're saying
>the same thing about Boost that you're saying about more modern
>C++ features: too complex and unnecessary.
 
Its more a case of use where appropriate, not simply because you want to look
like a rockstar coder.
 
>Using modern language usually results in less code and sometimes
>just more portable code.
 
As I've already said, a regex can in theory dispense with a huge amount of
code. But sometimes that code would be more intelligable not to mention
flexible.
Mr Flibble <flibble2@reddwarf.jmc.corp>: Apr 22 04:20PM +0100

> set up its values thats already more expensive that just updating a
> reference without the create. Then you have to add the cost of doing the
> move upon return. Despite what some people seem to think, move isn't costless.
 
With NRVO you might think you are creating the local object/array in the
stack frame of the current function but with NRVO you are actually
creating it in the caller's stack frame, so zero cost.
 
 
>> also; additionally, out parameters can be problematic for the optimiser.
 
> Optimisers are a black box. The only way you can know which approach is faster
> is try both.
 
It is well known that out parameters can be problematic for optimisers.
 
/Flibble
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 05:27PM +0200


> Sure you can ,but if you have a deadline you really don't want to
> have to dig into some obtuse syntax to figure out what its doing.
 
If you have a deadline it's good to learn things which save time.
 
> Its more a case of use where appropriate, not simply because you
> want to look like a rockstar coder.
 
Demanding C++17 skills isn't like looking for a rockstar coder.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 05:47PM +0200

And you're overburdened with std::expected, which is rather a
variant<> with two variables. You can check it from cpppreference
in 5min. And you're saying that needs a "rockstar developer" ?
I guess you're not developing software at all.
Muttley@dastardlyhq.com: Apr 22 04:15PM

On Sat, 22 Apr 2023 16:20:24 +0100
 
>With NRVO you might think you are creating the local object/array in the
>stack frame of the current function but with NRVO you are actually
>creating it in the caller's stack frame, so zero cost.
 
That depends on whether the compiler does it and if you're writing code for
some system where optimisation is low or switched off for some reason (usually
odd compiler bugs in edge cases) then it won't happen anyway.
Muttley@dastardlyhq.com: Apr 22 04:18PM

On Sat, 22 Apr 2023 17:27:29 +0200
 
>> Its more a case of use where appropriate, not simply because you
>> want to look like a rockstar coder.
 
>Demanding C++17 skills isn't like looking for a rockstar coder.
 
There are many useful things in C++ 17 such as shared_mutex so C++ threads
could finally manage 3 level locking (decades after pthreads), conditional
compilation of constexprs etc, but some of the stuff you post up is just
obfuscation for its own sake.
Mr Flibble <flibble2@reddwarf.jmc.corp>: Apr 22 05:23PM +0100


> That depends on whether the compiler does it and if you're writing code for
> some system where optimisation is low or switched off for some reason (usually
> odd compiler bugs in edge cases) then it won't happen anyway.
 
We should primarily be concerned with the general case, not the obscure
edge case.
 
/Flibble
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 06:38PM +0200

> could finally manage 3 level locking (decades after pthreads), conditional
> compilation of constexprs etc, but some of the stuff you post up is just
> obfuscation for its own sake.
 
Everything you're not familiar with is obfuscation.
std::expected<> is that simple and you didn't take 5min to look the doc.
Lynn McGuire <lynnmcguire5@gmail.com>: Apr 21 09:04PM -0500

"Windows 11 Version Detection" by Shao Voon Wong

https://www.codeproject.com/Articles/5336372/Windows-11-Version-Detection
 
"In this article, you will see how to detect Windows 11 Version by using
C# and C++."
 
Cool. There are some nuances there.
 
Lynn
gazelle@shell.xmission.com (Kenny McCormack): Apr 22 03:06PM

In article <u1vfb4$33k92$2@dont-email.me>,
>"Windows 11 Version Detection" by Shao Voon Wong
 
Off topic. Keith will explain it to you.
 
OT in both groups, but even moreso in CLC (where I am reading it).
 
--
The people who were, are, and always will be, wrong about everything, are still
calling *us* "libtards"...
 
(John Fugelsang)
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 04:39AM +0200

Am 21.04.2023 um 22:30 schrieb Mr Flibble:
 
> The cost of throwing an exception is not important as exceptions are
> supposed to be rare (exceptional - the clue is in the name) events; ...
 
I know that, but Muttley@... suggested in another posting always
to use exceptions instead of error return values. I've shown that
this doesn't make sense.
Mr Flibble <flibble2@reddwarf.jmc.corp>: Apr 22 05:44AM +0100

On 22/04/2023 3:39 am, Bonita Montero wrote:
 
> I know that, but Muttley@... suggested in another posting always
> to use exceptions instead of error return values. I've shown that
> this doesn't make sense.
 
Wrong. Always using exceptions instead of ERROR return values is
perfectly fine because ERRORS, like exceptions, should be rare
(exceptional) events.
 
/Flibble
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 08:16AM +0200

Am 22.04.2023 um 06:44 schrieb Mr Flibble:
 
> Wrong. Always using exceptions instead of ERROR return values is
> perfectly fine because ERRORS, like exceptions, should be rare
> (exceptional) events.
 
Look at how Java uses exceptions where in C++ you'd use return-values.
That's while exceptions in Java are magnitudes faster (the language
itsef aint't faster). If you would do that in C++, like Muttley sug-
gested, you'd sometimes have performance problems.
Muttley@dastardlyhq.com: Apr 22 09:18AM

On Fri, 21 Apr 2023 19:30:42 +0200
>Am 21.04.2023 um 15:45 schrieb Muttley@dastardlyhq.com:
 
>> No muttley didn't think that. ...
 
>You suggested to use exceptions for return-values.
 
No, I suggested them for errors. Learn to read.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 22 01:13PM +0200


> No, I suggested them for errors. Learn to read.
 
That's what I said or didn't mean, that using exceptions for
return values should be obvious anyway. But using exceptions
to inform the immediate caller doesn't make sense.
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.

Thursday, April 20, 2023

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

even andersen <even.oscar.andersen@gmail.com>: Apr 20 01:49PM -0700

søndag 12. mars 2023 kl. 13:42:06 UTC+1 skrev Frederick Virchanza Gotham:
> I mentioned a few weeks ago on this newsgroup about how I'm combining two programs into one.
 
...
> stdout = f;
Not sure the above is legal.
 
As far as I know this cannot be done in neither C nor C++, it can be done in posix
 
(For reference, and since the question was asked, not really c++ though)
(For instance https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html)
 
You might want to work on the right hand side of the filedescriptor table, assuming:
(FILE *) / iostream ---> <file descriptor> ---> (client side object) ---> | ---> (kernel side object)
 
with this model you would look at:
pipe(2)
dup(2)
dup2(2)
(dup3(2))
close(2)
read(2)
write(2)
flockfile(3) / funlockfile(3)
fflush(3)
fdopen(3)
 
This way you would:
Keep stdout as is
Keep fileno(stdout) as is
Redirect what fileno(stdout) refers to
 
stdout -> | fileno(stdout) | (some object)
| fd_1 | ^
| pipe_wr | >---V
| pipe_rd | <---V
 
stdout -> | fileno(stdout) | (rewired to refer to pipe_wr)
| fd_1 | (refers to old stdout object)
| pipe_wr | >---V
| pipe_rd | <---V
 
 
1) Duplicate fileno(stdout) to keep it around (create a new fd to the client side object) (dup)
2) Create a pipe, with a read end and a write end (create two fds to a new client side object) (pipe)
3) Change fileno(stdout) to refer to the write end of the pipe above (dup2)
4) Read from the read end of the pipe,
-> this is where you capture what is written to stdout, and fileno(stdout)
5) Process what you read, and write it to the filedescriptor you duplicated in 1)
 
 
The problem with this approach is that the object layout/processing layout is not specified for C or C++.
Another weak point is that std::cout etc does not necessarily write to stdout/fileno(stdout)
 
(Not really c++ though)
 
And if you want it standardized, try this pipeline
(buffered layer) -> (file descriptor layer) -> (client side object) -> (kernel side object)
 
.. or write a library
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Apr 20 01:04PM -0700


> I don't know about you but I'm quite glad the language models still generate
> rubbish code. They day they start generating efficient working code based on
> a simple request we're all out of a job.
 
If I were to teach it how to give a correct answer, that would just help
it put us out of a job. Yikes! ;^o
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Apr 20 01:08PM -0700

On 4/20/2023 1:04 PM, Chris M. Thomasson wrote:
>> a simple request we're all out of a job.
 
> If I were to teach it how to give a correct answer, that would just help
> it put us out of a job. Yikes! ;^o
 
So far, it seems to have a hard time creating multi-threaded
synchronization algorithms. It gets the memory barriers off, amongst
other things... Now, if I were to show it where it went wrong, that
would be teaching it. Why would I want to help it put programmers out of
a job?
Muttley@dastardlyhq.com: Apr 20 03:58PM

On Thu, 20 Apr 2023 16:59:59 +0200
>> std::optionals entire use case is functions that return simple values where
>> a success/failure boolean is required too.
 
>Perhaps you got that idea from working with old C compilers and old C
 
Nope.
 
>std::optional<> is extremely convenient. It is mostly just a wrapper
 
Its an ugly mess. value()/value_or(), exception handling required, seriously?
Thanks, but I'll stick with a simple bool return value.
Muttley@dastardlyhq.com: Apr 20 04:10PM

On Thu, 20 Apr 2023 18:01:46 +0200
>>> It seems that everything that overwhelms you is pointless technology.
 
>> Unlike you I write code to do a job, not with an obfuscated fashion show.
 
>This "obfuscation" saves work.
 
Not when some poor sod has to decode the gibberish to figure out what it
actually does (which in your case is usually very little, all show and no go).
Muttley@dastardlyhq.com: Apr 20 04:11PM

On Thu, 20 Apr 2023 18:03:11 +0200
 
>> Its an ugly mess. value()/value_or(), exception handling required, seriously?
 
>> Thanks, but I'll stick with a simple bool return value.
 
>The type of error may be relevant to a user.
 
Then throw a standard exception, don't have some frankenstein combination of
std::optional return value then a potential exception when you try to process
it.
David Brown <david.brown@hesbynett.no>: Apr 20 06:13PM +0200


> Nope.
 
>> std::optional<> is extremely convenient. It is mostly just a wrapper
 
> Its an ugly mess. value()/value_or(), exception handling required, seriously?
 
No, I assume you are not being serious.
 
I use it in my embedded systems, with exceptions disabled, and it is
simple, convenient in the code, and efficient in the implementation.
 
You only need exceptions if you like to program by crashing ahead
blindly, and trying to clear up the mess when something goes wrong -
such as by using the "value()" method without bothering to check for
validity. That would, of course, defeat the whole point of using optionals.
 
 
Typical usage for me is :
 
extern std::optional<Item> get_next_item();
 
 
auto item = get_next_item();
if (item) handle(*item);
 
or :
 
if (auto item = get_next_item(); item) handle(item);
 
 
Sometimes I will use value_or() :
 
auto config_port = get_config("port number");
open_port(config_port.value_or(default_port_no));
 
It is much cleaner and simpler than faffing around with passing pointers
and using bool returns, is often more efficient, and works better with
static error checking (such as checking for initialised variables).
 
 
Bonita Montero <Bonita.Montero@gmail.com>: Apr 20 06:37PM +0200


>>> Thanks, but I'll stick with a simple bool return value.
 
>> The type of error may be relevant to a user.
 
> Then throw a standard exception, ...
 
Thrown exceptions are extremely slow (> 10.000 cycles) and
often the return value should be passed directly to the caller.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 20 06:38PM +0200


> Not when some poor sod has to decode the gibberish to figure out what it
> actually does ...
That's not a big deal if you know the language.
Paavo Helde <eesnimi@osa.pri.ee>: Apr 20 08:22PM +0300


> or
 
> 2) Update reference array directly.
 
> Which do you think is more efficient?
 
Local C array of 1 billion elements would run out of stack space,
regardless of whether it resides in the leaf function or in the calling
function.
 
Ergo, one would need to use a std::vector instead, which can be returned
efficiently. Thus there is no reason to use a reference parameter.
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.