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.

No comments: