- Best C++20 feature - 9 Updates
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 26 03:42PM +0100 By far and away the best C++20 feature is strong typedefs: we have been waiting so long for this feature and it has finally arrived: strong typedef int wibble_t; void foo(int i) {} void foo(wibble_t w) {} // this overload is called! \o/ wibble_t w = 42; foo(w); /Flibble -- "Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
Thiago Adams <thiago.adams@gmail.com>: Jul 26 09:23AM -0700 On Friday, July 26, 2019 at 11:42:21 AM UTC-3, Mr Flibble wrote: > By far and away the best C++20 feature is strong typedefs: we have been > waiting so long for this feature and it has finally arrived: > strong typedef int wibble_t; Where did you hear about it? Is this a joke? |
Robert Wessel <robertwessel2@yahoo.com>: Jul 26 11:58AM -0500 On Fri, 26 Jul 2019 15:42:09 +0100, Mr Flibble >void foo(wibble_t w) {} // this overload is called! \o/ >wibble_t w = 42; >foo(w); Surely it would have been better to not introduce a new keyword, and rather add another meaning for static. ;-) |
Bonita Montero <Bonita.Montero@gmail.com>: Jul 26 07:41PM +0200 Am 26.07.2019 um 16:42 schrieb Mr Flibble: > By far and away the best C++20 feature is strong typedefs: > we have been waiting so long for this feature and it has finally arrived: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I think this is a very special feature and not many have waited for this. |
Keith Thompson <kst-u@mib.org>: Jul 26 11:19AM -0700 >> strong typedef int wibble_t; > Where did you hear about it? > Is this a joke? It's not a joke, but only because jokes are funny. There is no "strong typedef" feature in C++, and no such feature will be in C++20. Apparently Boost has something called BOOST_STRONG_TYPEDEF, which has some limitations. There have been proposals for strong typedefs. See, for example, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3515.pdf (If I've missed something, and such a feature is proposed for C++20, please provide a citation.) (Recall that typedef does not define a new type, just a new name for an existing type.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */ |
Thiago Adams <thiago.adams@gmail.com>: Jul 26 12:24PM -0700 On Friday, July 26, 2019 at 3:19:33 PM UTC-3, Keith Thompson wrote: > please provide a citation.) > (Recall that typedef does not define a new type, just a new name for an > existing type.) I didn't find any c++ proposal for this feature and then I thought it was a joke. I think strong-typedefs are useful. In windows HRESULT and BOOL can be mixed causing errors, for instance. Some static analysis have this feature implemented: https://www.gimpel.com/html/strong.htm |
Bart <bc@freeuk.com>: Jul 26 09:21PM +0100 On 26/07/2019 20:24, Thiago Adams wrote: > it was a joke. > I think strong-typedefs are useful. In windows HRESULT and BOOL can > be mixed causing errors, for instance. HRESULT is defined as 'long', an int, so not that much can go wrong. It's also intended to hold a result, which can be 'bool'. But it's also misnamed as it is not a handle, which generally are pointers; those can't be mixed up with bools. > Some static analysis have this feature implemented: > https://www.gimpel.com/html/strong.htm That helps explain why Pascal could be such a pain to write. When you have a million little integer types, all different, and that must match exactly as well being able to interact, then life is necessarily more difficult. It's never that bad in real life: we don't use a different kind of number to index floors in a building, compared with pages in a book for example, but how many times does that cause a problem? In code, we can write: int page_number, floor_number to help out. |
Thiago Adams <thiago.adams@gmail.com>: Jul 26 01:34PM -0700 On Friday, July 26, 2019 at 5:22:14 PM UTC-3, Bart wrote: > > be mixed causing errors, for instance. > HRESULT is defined as 'long', an int, so not that much can go wrong. > It's also intended to hold a result, which can be 'bool'. if I remember correctly the error is something like this: HRESULT F() { ... return FALSE; } The value 0 means OK (S_OK) in HRESULT This code compiles without error or warning. > write: > int page_number, floor_number > to help out. If I had this feature I would not use for each type in the world. I would not use for kilos or meters (unless maybe doing some rocket code) because this increases the mental load to understand the program. If you read 'int meters' you have two good information. if you read 'Meters meters' you need to known exactly what is Meters. |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 27 12:03AM +0100 On 26/07/2019 17:58, Robert Wessel wrote: >> foo(w); > Surely it would have been better to not introduce a new keyword, and > rather add another meaning for static. ;-) Great minds think alike: I was going to subsequently reply that my post would have been more credible if I used "static" instead of "strong" due to the dearth of contextual meanings for the "static" keyword. :D /Flibble -- "Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Bryne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
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