- Operators for min/max, or min/max-assignment operators? - 10 Updates
- Improvements in the type system [Supersedes] - 2 Updates
- High horse - 1 Update
- [FYI] 1.68.0 deadline for new libraries approaching - 2 Updates
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 18 02:54PM -0400 Is there a native operator for min and max in C or C++? // Traditional way #define min(a, b) ((a <= b) ? a : b) #define max(a, b) ((a >= b) ? a : b) int a, b, c, d; a = 5; b = 8; // Assign min and max: c = min(a, b); d = max(a, b); Is there an operator for this? Like /\ for max, \/ for min? // Assign min and max using operators: c = a \/ b; d = a /\ b; Or min/max-assignment operators? // Min of b and a is assigned to b b \/= a; // Equivalent of b = min(b, a) // Max of b and a is assigned to b b /\= a; // Equivalent of b = max(b, a) -- Rick C. Hodgin |
Bart <bc@freeuk.com>: Jun 18 08:03PM +0100 On 18/06/2018 19:54, Rick C. Hodgin wrote: > Is there a native operator for min and max in C or C++? Not in C. (In C++ the answer to any such question is apparently always Yes. If it doesn't have it already, you can implement it.) > // Assign min and max: > c = min(a, b); d = max(a, b); > Is there an operator for this? Like /\ for max, \/ for min? Why not just call then max and min? Then everyone will immediately understand what they do. Anyway /\ and \/ won't work for obvious reasons. -- bart |
David Brown <david.brown@hesbynett.no>: Jun 18 09:33PM +0200 On 18/06/18 20:54, Rick C. Hodgin wrote: > // Traditional way > #define min(a, b) ((a <= b) ? a : b) > #define max(a, b) ((a >= b) ? a : b) Traditional C would be: #define MIN(a, b) (((a) <= (b)) ? (a) : (b)) #define MAX(a, b) (((a) >= (b)) ? (a) : (b)) In C++, you'd be better with a template. That would let you avoid the "min(a++, b++)" problem. If you are a gcc extension fan, you might also like their suggestion using "typeof": <https://gcc.gnu.org/onlinedocs/gcc/Typeof.html> > b \/= a; // Equivalent of b = min(b, a) > // Max of b and a is assigned to b > b /\= a; // Equivalent of b = max(b, a) gcc used to have "a <? b" as min(a, b) and "a >? b" as max(a, b), as an extension. They dropped it a good while ago. I don't know exactly why, but I expect it was very rarely used. |
Daniel <danielaparker@gmail.com>: Jun 18 12:37PM -0700 On Monday, June 18, 2018 at 2:54:55 PM UTC-4, Rick C. Hodgin wrote: > // Assign min and max: > c = min(a, b); d = max(a, b); > Is there an operator for this? Like /\ for max, \/ for min? No, but there are std::min and std::max, which are typically used as c = (std::min)(a,b); d = (std::max)(a,b); to avoid conflicts with min and max #defines. Daniel |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jun 18 03:52PM -0400 On 6/18/2018 3:03 PM, Bart wrote: >> c = min(a, b); d = max(a, b); >> Is there an operator for this? Like /\ for max, \/ for min? > Anyway /\ and \/ won't work for obvious reasons. Why wouldn't those character combinations work? -- Rick C. Hodgin |
"Öö Tiib" <ootiib@hot.ee>: Jun 18 01:10PM -0700 On Monday, 18 June 2018 22:37:25 UTC+3, Daniel wrote: > No, but there are std::min and std::max, which are typically used as > c = (std::min)(a,b); d = (std::max)(a,b); > to avoid conflicts with min and max #defines. Also it might be worth to note that several arguments can be supplied to std::min and std::max since C++14: auto m = std::max({a, b, c, d, e, f}); For sequences (or whole containers) there are std::min_element and std::max_element. If someone really wants to go nuts with custom operators then Swift is perhaps good language for them. To me such experiments look too cryptic and trying to remember keyboard shortcut for each dingbat is also annoying. I know Rick won't use Swift since he hates Apple for unknown reasons. |
scott@slp53.sl.home (Scott Lurndal): Jun 18 08:12PM >#define MAX(a, b) (((a) >= (b)) ? (a) : (b)) >In C++, you'd be better with a template. That would let you avoid the >"min(a++, b++)" problem. like std::min and std::max? |
scott@slp53.sl.home (Scott Lurndal): Jun 18 08:13PM >>> Is there an operator for this? Like /\ for max, \/ for min? >> Anyway /\ and \/ won't work for obvious reasons. >Why wouldn't those character combinations work? What is the meaning and purpose of the '\' character in C? |
Bart <bc@freeuk.com>: Jun 18 09:19PM +0100 On 18/06/2018 20:52, Rick C. Hodgin wrote: >>> Is there an operator for this? Like /\ for max, \/ for min? >> Anyway /\ and \/ won't work for obvious reasons. > Why wouldn't those character combinations work? Because \ is usually involved with line continuation. There would be ambiguities. -- bart |
red floyd <dont.bother@its.invalid>: Jun 18 03:44PM -0700 On 6/18/2018 12:03 PM, Bart wrote: > Why not just call then max and min? Then everyone will immediately > understand what they do. > Anyway /\ and \/ won't work for obvious reasons. Not to mention that the "correct" way to do the "traditional" way is #define min(a,b) (((a) <= (b)) ? (a) : (b)) #define max(a,b) (((a) >= (b)) ? (a) : (b)) |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jun 18 02:58PM On Fri, 2018-06-15, David Brown wrote: > mistake, but we /do/ care about posting like this. > Start a /single/ thread about what you think is new and cool about > upcoming C++ standards, and we can discuss that. Oddly, I don't have the original article on my news server -- possibly because it's the same one Stefan uses, and the archaic "supersedes" header worked locally. But I agree with you. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
David Brown <david.brown@hesbynett.no>: Jun 18 06:37PM +0200 On 18/06/18 16:58, Jorgen Grahn wrote: > Oddly, I don't have the original article on my news server -- possibly > because it's the same one Stefan uses, and the archaic "supersedes" > header worked locally. Ah, well - maybe he was trying to do the right thing. But superseding and deleting Usenet articles has not been supported on most servers for a very long time. I know that Stefan is a very positive contributor to this group - I'd hate to see him get killfiled by people due to a misunderstanding about Usenet posting. |
legalize+jeeves@mail.xmission.com (Richard): Jun 18 02:31PM [Please do not mail me a copy of your followup] Vir Campestris <vir.campestris@invalid.invalid> spake the secret code >But back to TDD. The hard problems to test for are timing issues. I have >no faith that any reasonable suite of tests will pick up complex races >or deadlocks. (Though TSAN helps) The best advice I've seen regarding threading/race issues is to isolate the threading logic separate from everything else, e.g. follow single responsibility principle. "Growing Object-Oriented Software, Guided by Tests" <https://amzn.to/2JXPyVI> and "Modern C++ Programming with Test-Driven Development" <https://amzn.to/2lir5ja> both touch on this, but I'm not aware of any systematic treatment by an automated testing framework for any language. For C++ we do have the sanitizers from clang, which is a great help. -- "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> |
boltar@cylonHQ.com: Jun 18 08:41AM On Fri, 15 Jun 2018 12:19:07 -0400 >> > represented nearly half of all smartwatch sales. >> Wow, half of all smartwatch sales! Thats like saying >half is incredibly good for a product that's been out for ~3 years. Given the other makers a bit players and the watches hard to get hold of in a lot of markets it should be way more than half. >> And thats just one model. >no, that's *not* just one model. Ok, one range out of many. >that's 100 million *total* since 1981, more than 35 years ago. Actualy its 1983 and the original g shock sold very few. And I wonder what the chances of the apple watch still being around in 35 years are? Or even apple? >> every day at work and used to own an iPad until I upgraded to android. >you were first with the fanboy comment, and if you actually used "os/x" >you'd know that it is not written that way. Its not written in lowercase either. And if you don't believe I use OS/X why not going and look up the posts I made in comp.unix.programmer about OS/X systems programming. |
boltar@cylonHQ.com: Jun 18 08:43AM On Fri, 15 Jun 2018 12:19:08 -0400 >nope. that would be you. >'real work' is different for different people and you aren't the one >who decides what is real work and what is not. So fill us in on what it is you do as a job then? My guess is you don't have one, you're a student. >it's also clear that you do not know how to use a mobile device to its >fullest potential. And its clear that you have no idea how real work most often requires decent input devices. There's a reason Windows 8 flopped big time on the desktop, why not go find out why. |
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:
Post a Comment