Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #88973 > unrolled thread
| Started by | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| First post | 2023-02-04 22:32 +0100 |
| Last post | 2023-03-07 17:37 +0100 |
| Articles | 20 on this page of 70 — 14 participants |
Back to article view | Back to comp.lang.c++
Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-04 22:32 +0100
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 15:37 +0100
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 22:45 +0100
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-02-05 12:49 -0800
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-05 22:39 +0100
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-06 22:09 +0100
Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-06 21:35 +0000
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-06 23:44 +0100
Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 01:34 +0000
Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-07 07:42 -0800
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-07 17:34 +0100
Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 07:51 -0800
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-24 18:48 +0100
Re: Found a use case for `const` by value return, a shared queue Daniel <danielaparker@gmail.com> - 2023-02-26 09:50 -0800
Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-05 08:38 -0800
Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-03-05 08:43 -0800
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-03-06 15:51 +0100
Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 16:35 +0000
Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-22 06:28 -0800
Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-22 15:01 +0000
Re: Found a use case for `const` by value return, a shared queue Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-02-24 08:34 -0800
Re: Found a use case for `const` by value return, a shared queue Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 01:02 +0200
Re: Found a use case for `const` by value return, a shared queue scott@slp53.sl.home (Scott Lurndal) - 2023-02-07 01:27 +0000
Re: Found a use case for `const` by value return, a shared queue Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 08:55 +0200
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-02-07 12:11 -0800
Re: Found a use case for `const` by value return, a shared queue James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-02-07 00:19 -0500
Re: Found a use case for `const` by value return, a shared queue Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 21:41 -0800
Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 16:49 +0000
Re: Found a use case for `const` by value return, a shared queue red floyd <no.spam.here@its.invalid> - 2023-02-08 11:11 -0800
Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-09 00:40 +0000
Re: Found a use case for `const` by value return, a shared queue Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-08 17:15 -0800
Re: Found a use case for `const` by value return, a shared queue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-09 03:07 +0000
Re: Found a use case for `const` by value return, a shared queue "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-02-09 04:54 +0100
Re: Found a use case for `const` by value return, a shared queue Öö Tiib <ootiib@hot.ee> - 2023-02-08 23:38 -0800
Re: Found a use case for `const` by value return, a shared queue David Brown <david.brown@hesbynett.no> - 2023-02-09 09:10 +0100
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-03 19:51 +0100
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-03 12:45 -0800
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 05:38 +0100
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-04 15:25 -0800
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-05 05:19 +0100
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-05 13:41 -0800
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 16:11 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 09:53 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 15:38 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 15:28 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 17:17 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 16:21 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 17:39 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 16:57 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:06 +0100
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:10 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-04 17:14 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 18:41 +0100
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-04 20:07 +0100
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-04 15:26 -0800
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-05 05:18 +0100
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-05 13:37 -0800
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 05:52 +0100
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-06 15:29 -0800
Re: Found a use case for `const` by value return, a shared queue "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-03-06 15:42 -0800
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 09:18 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 11:18 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 10:26 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-06 16:10 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-06 17:07 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 06:44 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-07 09:31 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 14:45 +0100
Re: Found a use case for `const` by value return, a shared queue Muttley@dastardlyhq.com - 2023-03-07 15:59 +0000
Re: Found a use case for `const` by value return, a shared queue Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-07 17:37 +0100
Page 2 of 4 — ← Prev page 1 [2] 3 4 Next page →
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2023-02-24 08:34 -0800 |
| Message-ID | <86bkljaupw.fsf@linuxsc.com> |
| In reply to | #89205 |
scott@slp53.sl.home (Scott Lurndal) writes: > Tim Rentsch <tr.17687@z991.linuxsc.com> writes: > >> scott@slp53.sl.home (Scott Lurndal) writes: >> >>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes: >>> >>>> "Alf P. Steinbach" <alf.p.steinbach@gmail.com> writes: >>>> >>>>> On 2023-02-06 10:35 PM, Scott Lurndal wrote: >>>> >>>> [...] >>>> >>>>>> Whatever agent you used to post this wrapped many of the longer lines >>>>> >>>>> The agent is Mozilla Thunderbird. >>>>> >>>>> It uses a line continuation scheme that's specified in RFC 3676 >>>>> section 4.1, of putting a space at the end of a line as continuation >>>>> symbol; <url: https://www.ietf.org/rfc/rfc3676.txt>. >>>>> >>>>> That's called a "soft line break", and the scheme is called "flowed >>>>> format", which you can see in the posting's headers. >>>>> >>>>> Thus, looking at my posting in TB's usual view it's fine, but the raw >>>>> posted text lines are wrapped. >>>> >>>> Unfortunately some or many of those trailing spaces don't >>>> survive getting to the client newsreader in the first place. >>>> I've looked carefully. In many cases where the lines are >>>> wrapped, the trailing spaces aren't there. >>>> >>>>> Evidently your newsreader XRN (X news reader) or perhaps your version >>>>> of that newsreader, doesn't support RFC 3676's flowed format. >>>> >>>> I've looked at the raw input, before it ever gets processed by >>>> the newsreader. On most of the wrapped lines, no trailing spaces. >>> >>> XRN doesn't "process" the message, it simply displays it as is. >> >> Surely displaying the message involves some processing, >> even if not very much. > > const char *source_pointer = source; > char *dest_pointer = dest; > > while (*source != '\0') *dest_pointer++ = *source_pointer++; > > I would call that moving the data, not processing the data. I think it's fair to say that any effort that involves activity by the processor may be called processing. Furthermore your earlier message says "displays". The code shown doesn't do any displaying.
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <eesnimi@osa.pri.ee> |
|---|---|
| Date | 2023-02-07 01:02 +0200 |
| Message-ID | <trs0ut$387vg$1@dont-email.me> |
| In reply to | #88996 |
06.02.2023 23:35 Scott Lurndal kirjutas: > > The idea that locking can be solved using RAII universally is unviable. Right, but in C++ we have the means and habits to encapsulate such non-RAII things in low-level classes like std::condition_variable::wait() et al, so the application level code can be clean and RAII.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2023-02-07 01:27 +0000 |
| Message-ID | <mOhEL.1039106$GNG9.733017@fx18.iad> |
| In reply to | #89000 |
Paavo Helde <eesnimi@osa.pri.ee> writes: >06.02.2023 23:35 Scott Lurndal kirjutas: >> >> The idea that locking can be solved using RAII universally is unviable. > >Right, but in C++ we have the means and habits to encapsulate such >non-RAII things in low-level classes like >std::condition_variable::wait() et al, so the application level code can >be clean and RAII. There are simple cases where that approach is sufficient. But as I noted above, it is not suitable for all cases. I've found it (RAII) more a hindrence than an aid in most real world (locking) cases. Either it forces clumsy/exessive source code or it expands the size of the critical region; the former hinders maintenance, the latter, performance. I'd much rather see explicit lock/unlock calls used to minimize the critical region rather than having every exit from a scope automatically releasing one or more locks. While I tend to avoid nesting locks, there are many cases where they make sense and for deadlock avoidance the order of acquisition and release becomes key; something that RAII may not be suitable to control.
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <eesnimi@osa.pri.ee> |
|---|---|
| Date | 2023-02-07 08:55 +0200 |
| Message-ID | <trsslb$3ffbm$1@dont-email.me> |
| In reply to | #89001 |
07.02.2023 03:27 Scott Lurndal kirjutas: > Paavo Helde <eesnimi@osa.pri.ee> writes: >> 06.02.2023 23:35 Scott Lurndal kirjutas: >>> >>> The idea that locking can be solved using RAII universally is unviable. >> >> Right, but in C++ we have the means and habits to encapsulate such >> non-RAII things in low-level classes like >> std::condition_variable::wait() et al, so the application level code can >> be clean and RAII. > > There are simple cases where that approach is sufficient. But as I > noted above, it is not suitable for all cases. I've found it (RAII) more > a hindrence than an aid in most real world (locking) cases. Either it forces > clumsy/exessive source code or it expands the size of the critical region; the former > hinders maintenance, the latter, performance. I'd much rather see explicit > lock/unlock calls used to minimize the critical region rather than having > every exit from a scope automatically releasing one or more locks. > > While I tend to avoid nesting locks, there are many cases where they > make sense and for deadlock avoidance the order of acquisition and release > becomes key; something that RAII may not be suitable to control. For that scenario there is std::scoped_lock (C++17) - "deadlock-avoiding RAII wrapper for multiple mutexes". It calls the std::lock() function which "Locks the given Lockable objects lock1, lock2, ..., lockn using a deadlock avoidance algorithm to avoid deadlock." These quotes are from https://en.cppreference.com It looks like that at least the committee thinks RAII and nested locks are not contradictory.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2023-02-07 12:11 -0800 |
| Message-ID | <trub9s$3rom8$3@dont-email.me> |
| In reply to | #89006 |
On 2/6/2023 10:55 PM, Paavo Helde wrote: > 07.02.2023 03:27 Scott Lurndal kirjutas: >> Paavo Helde <eesnimi@osa.pri.ee> writes: >>> 06.02.2023 23:35 Scott Lurndal kirjutas: >>>> >>>> The idea that locking can be solved using RAII universally is unviable. >>> >>> Right, but in C++ we have the means and habits to encapsulate such >>> non-RAII things in low-level classes like >>> std::condition_variable::wait() et al, so the application level code can >>> be clean and RAII. >> >> There are simple cases where that approach is sufficient. But as I >> noted above, it is not suitable for all cases. I've found it (RAII) >> more >> a hindrence than an aid in most real world (locking) cases. Either it >> forces >> clumsy/exessive source code or it expands the size of the critical >> region; the former >> hinders maintenance, the latter, performance. I'd much rather see >> explicit >> lock/unlock calls used to minimize the critical region rather than having >> every exit from a scope automatically releasing one or more locks. >> >> While I tend to avoid nesting locks, there are many cases where they >> make sense and for deadlock avoidance the order of acquisition and >> release >> becomes key; something that RAII may not be suitable to control. > > For that scenario there is std::scoped_lock (C++17) - "deadlock-avoiding > RAII wrapper for multiple mutexes". > > It calls the std::lock() function which "Locks the given Lockable > objects lock1, lock2, ..., lockn using a deadlock avoidance algorithm to > avoid deadlock." Iirc, it uses a retry and backoff algorithm. There is another way using address based hash locks where the locks are sorted and duplicates are removed. It always preserves a strict locking order. A thread can take several locks without fear of deadlock: https://groups.google.com/g/comp.lang.c++/c/sV4WC_cBb9Q/m/Ti8LFyH4CgAJ > > These quotes are from https://en.cppreference.com > > It looks like that at least the committee thinks RAII and nested locks > are not contradictory. >
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2023-02-07 00:19 -0500 |
| Message-ID | <trsn1s$3el73$1@dont-email.me> |
| In reply to | #88996 |
On 2/6/23 16:35, Scott Lurndal wrote:
...
> I don't recall 'not', 'and' and 'or' being C++ keywords.
Table 1 in the C++ standard lists alternatives for many tokens:
<% {
%> }
<: [
:> ]
%: #
%:%: ##
and &&
bitor |
or ||
xor ^
compl ~
bitand &
and_eq &=
or_eq |=
xor_eq ^=
not !
not_eq !=
These go way back - "The Design and Evolution of C++" describes them. My
copy of "The C++ Programming Language" and the first version of the C++
standard have unfortunately both gone missing, so I can't confirm
whether they were introduced by that standard, or earlier.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2023-02-06 21:41 -0800 |
| Message-ID | <87ilgedoc5.fsf@nosuchdomain.example.com> |
| In reply to | #89003 |
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 2/6/23 16:35, Scott Lurndal wrote:
> ...
>> I don't recall 'not', 'and' and 'or' being C++ keywords.
>
> Table 1 in the C++ standard lists alternatives for many tokens:
> <% {
> %> }
> <: [
> :> ]
> %: #
> %:%: ##
> and &&
> bitor |
> or ||
> xor ^
> compl ~
> bitand &
> and_eq &=
> or_eq |=
> xor_eq ^=
> not !
> not_eq !=
>
> These go way back - "The Design and Evolution of C++" describes them. My
> copy of "The C++ Programming Language" and the first version of the C++
> standard have unfortunately both gone missing, so I can't confirm
> whether they were introduced by that standard, or earlier.
They're in the 1998 ISO C++ standard (2.5 [lex.digraph]).
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2023-02-08 16:49 +0000 |
| Message-ID | <87lel8kspr.fsf@bsb.me.uk> |
| In reply to | #89003 |
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 2/6/23 16:35, Scott Lurndal wrote:
> ...
>> I don't recall 'not', 'and' and 'or' being C++ keywords.
>
> Table 1 in the C++ standard lists alternatives for many tokens:
> <% {
> %> }
> <: [
> :> ]
> %: #
> %:%: ##
> and &&
> bitor |
> or ||
> xor ^
> compl ~
> bitand &
> and_eq &=
> or_eq |=
> xor_eq ^=
> not !
> not_eq !=
>
> These go way back - "The Design and Evolution of C++" describes them. My
> copy of "The C++ Programming Language" and the first version of the C++
> standard have unfortunately both gone missing,
I have the second edition of that book (1991) and they are not
mentioned. I don't recall when they came along but, as Keith as said,
there were there by the first C++ ISO standard (1998).
The names are a bit confusing because not_eq and and_eq share an ending
but one is about equality and the other about assignment.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2023-02-08 11:11 -0800 |
| Message-ID | <ts0s45$a0o6$1@redfloyd.dont-email.me> |
| In reply to | #89040 |
On 2/8/2023 8:49 AM, Ben Bacarisse wrote: > The names are a bit confusing because not_eq and and_eq share an ending > but one is about equality and the other about assignment. > I think they chose those expansions because they match how people would say those operators when reading code out loud.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2023-02-09 00:40 +0000 |
| Message-ID | <87r0uzk6wd.fsf@bsb.me.uk> |
| In reply to | #89043 |
red floyd <no.spam.here@its.invalid> writes: > On 2/8/2023 8:49 AM, Ben Bacarisse wrote: > >> The names are a bit confusing because not_eq and and_eq share an ending >> but one is about equality and the other about assignment. >> > > I think they chose those expansions because they match how people would > say those operators when reading code out loud. Yes, I imagine that's the motivation (with "equals" abbreviated). But I don't read = as "equals". I read it as "is" or "becomes" depending on whether it's in an initialisation or an assignment, so and_eq sounds all wrong to me. It's "bitwise and becomes" when I have to read it out. And it's odd that &&= and ||= don't get alternatives. OK, much less frequently used, so I suppose that's why. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2023-02-08 17:15 -0800 |
| Message-ID | <871qmzej08.fsf@nosuchdomain.example.com> |
| In reply to | #89047 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> red floyd <no.spam.here@its.invalid> writes:
>> On 2/8/2023 8:49 AM, Ben Bacarisse wrote:
>>> The names are a bit confusing because not_eq and and_eq share an ending
>>> but one is about equality and the other about assignment.
>>
>> I think they chose those expansions because they match how people would
>> say those operators when reading code out loud.
>
> Yes, I imagine that's the motivation (with "equals" abbreviated). But I
> don't read = as "equals". I read it as "is" or "becomes" depending on
> whether it's in an initialisation or an assignment, so and_eq sounds all
> wrong to me. It's "bitwise and becomes" when I have to read it out.
>
> And it's odd that &&= and ||= don't get alternatives. OK, much less
> frequently used, so I suppose that's why.
I suggest that they're rarely used because they don't exist. (Perl does
have them, but C++ does not.)
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2023-02-09 03:07 +0000 |
| Message-ID | <87wn4riljo.fsf@bsb.me.uk> |
| In reply to | #89048 |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >> red floyd <no.spam.here@its.invalid> writes: >>> On 2/8/2023 8:49 AM, Ben Bacarisse wrote: >>>> The names are a bit confusing because not_eq and and_eq share an ending >>>> but one is about equality and the other about assignment. >>> >>> I think they chose those expansions because they match how people would >>> say those operators when reading code out loud. >> >> Yes, I imagine that's the motivation (with "equals" abbreviated). But I >> don't read = as "equals". I read it as "is" or "becomes" depending on >> whether it's in an initialisation or an assignment, so and_eq sounds all >> wrong to me. It's "bitwise and becomes" when I have to read it out. >> >> And it's odd that &&= and ||= don't get alternatives. OK, much less >> frequently used, so I suppose that's why. > > I suggest that they're rarely used because they don't exist. (Perl does > have them, but C++ does not.) Ah! Good spot, thanks. I must have just assumed... -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2023-02-09 04:54 +0100 |
| Message-ID | <ts1qpk$hsr3$1@dont-email.me> |
| In reply to | #89051 |
On 2023-02-09 4:07 AM, Ben Bacarisse wrote: > Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: > >> Ben Bacarisse <ben.usenet@bsb.me.uk> writes: >>> red floyd <no.spam.here@its.invalid> writes: >>>> On 2/8/2023 8:49 AM, Ben Bacarisse wrote: >>>>> The names are a bit confusing because not_eq and and_eq share an ending >>>>> but one is about equality and the other about assignment. >>>> >>>> I think they chose those expansions because they match how people would >>>> say those operators when reading code out loud. >>> >>> Yes, I imagine that's the motivation (with "equals" abbreviated). But I >>> don't read = as "equals". I read it as "is" or "becomes" depending on >>> whether it's in an initialisation or an assignment, so and_eq sounds all >>> wrong to me. It's "bitwise and becomes" when I have to read it out. >>> >>> And it's odd that &&= and ||= don't get alternatives. OK, much less >>> frequently used, so I suppose that's why. >> >> I suggest that they're rarely used because they don't exist. (Perl does >> have them, but C++ does not.) > > Ah! Good spot, thanks. I must have just assumed... C++ also lacks a boolean XOR-operator, though it has a bitwise one. Weird. For the boolean XOR one can use `!=`, but it has ungood precedence. :( I don't know of any language that has an general either-or operator, one that lets you write `a $ b $ c` with meaning `!!a + !!b + !!c == 1`. Oh, and power-of operator. Power-of / raised to is really sorely needed, and the trick of writing e.g. `%rt%` (raised to) has problems beyond being misinterpreted as placement advertisement for a certain news organization. - Alf
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2023-02-08 23:38 -0800 |
| Message-ID | <bc2ef346-98d3-4604-b7c8-b8f6edf827e9n@googlegroups.com> |
| In reply to | #89054 |
On Thursday, 9 February 2023 at 05:54:43 UTC+2, Alf P. Steinbach wrote: > C++ also lacks a boolean XOR-operator, though it has a bitwise one. Weird. > > For the boolean XOR one can use `!=`, but it has ungood precedence. :( > How != has bad precedence? It is among most frequently used operators. What would be more intuitive precedence for it?
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2023-02-09 09:10 +0100 |
| Message-ID | <ts29q6$k6o5$1@dont-email.me> |
| In reply to | #89057 |
On 09/02/2023 08:38, Öö Tiib wrote: > On Thursday, 9 February 2023 at 05:54:43 UTC+2, Alf P. Steinbach wrote: >> C++ also lacks a boolean XOR-operator, though it has a bitwise one. Weird. >> >> For the boolean XOR one can use `!=`, but it has ungood precedence. :( >> > How != has bad precedence? It is among most frequently used > operators. What would be more intuitive precedence for it? I believe the point was he wanted a ^^ operator bearing the same relationship to ^ as && bears to &, and || bears to |. His thought was that != could be used instead. However, != has precedence matching ==, above the bitwise operators which are in turn above the logical and and or operators. To be consistent as a ^^ operator, you'd want something that had a similar precedence to && and ||. However, it is wrong to think that != could be used instead of ^^. For one thing, 4 != 2 is true, while bool(4) ^ bool(2) is false, so it would give the wrong answer. And one of the prime reasons for having && and || operators is their short-circuit evaluation, which would make no sense for an xor operation.
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2023-03-03 19:51 +0100 |
| Message-ID | <tttfgj$n1eb$1@dont-email.me> |
| In reply to | #88973 |
Use this thread-queue:
#pragma once
#include <deque>
#include <mutex>
#include <condition_variable>
#include <utility>
#include <concepts>
#include <list>
#include <deque>
#include "xscope.h"
template<typename Entity, typename Allocator = std::allocator<Entity>>
struct thread_queue
{
thread_queue();
explicit thread_queue( Allocator const &alloc );
thread_queue( thread_queue const & ) = delete;
thread_queue( thread_queue &&other );
thread_queue &operator =( thread_queue const & ) = delete;
thread_queue &operator =( thread_queue &&other );
bool empty() const;
size_t size() const;
void shrink_to_fit();
void clear();
template<typename ... Args>
#if defined(__cpp_concepts)
requires std::is_constructible_v<Entity, Args ...>
#endif
void enque( Args &&... args );
template<typename Producer>
requires requires( Producer producer ) { { producer() } ->
std::same_as<std::pair<bool, Entity>>; }
void enqueue_multiple( Producer &&producer );
template<typename Consumer>
#if defined(__cpp_concepts)
requires requires( Consumer consumer, Entity value ) { { consumer(
std::move( value ) ) } -> std::same_as<bool>; }
#endif
void dequeue_multiple( Consumer &&consumer );
Entity dequeue();
std::deque<Entity, Allocator> deque();
private:
mutable std::mutex m_mtx;
mutable std::condition_variable m_cv;
std::deque<Entity, Allocator> m_queue;
};
template<typename Entity, typename Allocator>
thread_queue<Entity, Allocator>::thread_queue()
{
}
template<typename Entity, typename Allocator>
thread_queue<Entity, Allocator>::thread_queue( Allocator const &alloc ) :
m_queue( alloc )
{
}
template<typename Entity, typename Allocator>
thread_queue<Entity, Allocator>::thread_queue( thread_queue &&other )
{
std::scoped_lock lock( m_mtx, other.m_mtx );
m_queue = move( other.m_queue );
}
template<typename Entity, typename Allocator>
thread_queue<Entity, Allocator> &thread_queue<Entity,
Allocator>::thread_queue::operator =( thread_queue &&other )
{
using namespace std;
lock_guard
ourLock( m_mtx ),
otherLock( other.m_mtx );
m_queue = move( other.m_queue );
return *this;
}
template<typename Entity, typename Allocator>
bool thread_queue<Entity, Allocator>::thread_queue::empty() const
{
std::lock_guard lock( m_mtx );
return m_queue.empty();
}
template<typename Entity, typename Allocator>
size_t thread_queue<Entity, Allocator>::thread_queue::size() const
{
std::lock_guard lock( m_mtx );
return m_queue.size();
}
template<typename Entity, typename Allocator>
void thread_queue<Entity, Allocator>::thread_queue::shrink_to_fit()
{
#if defined(__cpp_concepts)
if constexpr( requires() { { m_queue.shrink_to_fit() }; } )
#endif
{
std::lock_guard lock( m_mtx );
return m_queue.shrink_to_fit();
}
}
template<typename Entity, typename Allocator>
void thread_queue<Entity, Allocator>::thread_queue::clear()
{
std::lock_guard lock( m_mtx );
m_queue.clear();
}
template<typename Entity, typename Allocator>
template<typename ... Args>
#if defined(__cpp_concepts)
requires std::is_constructible_v<Entity, Args ...>
#endif
void thread_queue<Entity, Allocator>::thread_queue::enque( Args &&... args )
{
using namespace std;
unique_lock lock( m_mtx );
m_queue.emplace_front( forward<Args>( args ) ... );
m_cv.notify_one();
}
template<typename Entity, typename Allocator>
Entity thread_queue<Entity, Allocator>::thread_queue::dequeue()
{
using namespace std;
unique_lock lock( m_mtx );
while( m_queue.empty() )
m_cv.wait( lock );
Entity value = move( m_queue.back() );
m_queue.pop_back();
return value;
}
template<typename Entity, typename Allocator>
template<typename Producer>
#if defined(__cpp_concepts)
requires requires( Producer producer ) { { producer() } ->
std::same_as<std::pair<bool, Entity>>; }
#endif
void thread_queue<Entity, Allocator>::enqueue_multiple( Producer
&&producer )
{
std::lock_guard lock( m_mtx );
for( std::pair<bool, Entity> ret; (ret = move( producer() )).first; )
m_queue.emplace_front( move( ret.second ) ),
m_cv.notify_one();
}
template<typename Entity, typename Allocator>
template<typename Consumer>
#if defined(__cpp_concepts)
requires requires( Consumer consumer, Entity value ) { { consumer(
std::move( value ) ) } -> std::same_as<bool>; }
#endif
void thread_queue<Entity, Allocator>::dequeue_multiple( Consumer
&&consumer )
{
using namespace std;
unique_lock lock( m_mtx );
for( ; ; )
{
while( m_queue.empty() )
m_cv.wait( lock );
xscope_exit popBack( [&]() { m_queue.pop_back(); } );
if( !consumer( move( m_queue.back() ) ) )
return;
}
}
template<typename Entity, typename Allocator>
std::deque<Entity, Allocator> thread_queue<Entity, Allocator>::deque()
{
using namespace std;
unique_lock lock( m_mtx );
return move( m_queue );
}
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2023-03-03 12:45 -0800 |
| Message-ID | <tttm91$nmp5$1@dont-email.me> |
| In reply to | #89412 |
On 3/3/2023 10:51 AM, Bonita Montero wrote: > Use this thread-queue: [...] Not until you model it in something like Relacy. No time right now to read all of your code and verify it.
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2023-03-04 05:38 +0100 |
| Message-ID | <ttuhsn$t4mu$1@dont-email.me> |
| In reply to | #89414 |
Am 03.03.2023 um 21:45 schrieb Chris M. Thomasson: > Not until you model it in something like Relacy. > No time right now to read all of your code and verify it. Sorry, the code is trivial from the MT-perspective.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2023-03-04 15:25 -0800 |
| Message-ID | <tu0k13$13eme$1@dont-email.me> |
| In reply to | #89419 |
On 3/3/2023 8:38 PM, Bonita Montero wrote: > Am 03.03.2023 um 21:45 schrieb Chris M. Thomasson: > >> Not until you model it in something like Relacy. >> No time right now to read all of your code and verify it. > > Sorry, the code is trivial from the MT-perspective. > > I have seen too many bugs in code that others have labeled trivial before... Btw, I am busy on another project. :^)
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2023-03-05 05:19 +0100 |
| Message-ID | <tu155b$17p9j$2@dont-email.me> |
| In reply to | #89437 |
Am 05.03.2023 um 00:25 schrieb Chris M. Thomasson: > I have seen too many bugs in code that others have labeled > trivial before... Btw, I am busy on another project. :^) Idiot. You didn't have a look at my code.
[toc] | [prev] | [next] | [standalone]
Page 2 of 4 — ← Prev page 1 [2] 3 4 Next page →
Back to top | Article view | comp.lang.c++
csiph-web