Open utterances-bot opened 2 years ago
Greetings Kind Regards Thank You for another helpful article . May I please inquire the definition of "SignedIntegral" Thank You Kindly
An integral type is any of the type bool, char, char8_t (since C++20), char16_t, char32_t, wchar_t, short, int, long, long long, or any implementation-defined extended integer types, including any signed, unsigned, and cv-qualified variants.
Therefore a Signed Integral are the signed versions of these underlying types. Likewise Unsigned Integral are the unsigned versions.
Fantastic article. I want to know what the font of the code is :)
@rhcher: your browser's default monospace font
@PaltryProgrammer - the text is updated and I showed more code for this SignedIntegral concept. Thank you @2kaud for your explanation before the update happened!
Re 20). The whole issue of mixed signed/unsigned is a right rabbit hole that is best avoided. People have been known to be lost for days in one and then emerge screaming and a gibbering wreck....
Re 20) Another C++ shoot in the foot...
Re 20) Instead of having one fnc called cmp and returning ordering, we have again number of functions... C++ committee will never learn.
The underlying issue - which AFAIK has always been present - is that when mixed signed/unsigned operations are undertaken, the signed is 'promoted' to unsigned. Consider this:
#include <iostream>
int main() {
signed s {-100};
unsigned u {10};
std::cout << s * u << '\n';
}
What is the output? If anyone says -1000 then go and stand in the corner! On my computer it displays 4294966296! This is because the -100 is 'promoted' to a very high value positive unsigned number before the multiplication takes place and the result is unsigned. Ahhhh....l
The underlying issue - which AFAIK has always been present
Yes, it was always present. This is yet another example of C++ behavior that is unintuitive. C++ has virtually every possible default wrong. I used to love C++, but couple of years now observing what shambols it became due to the incompetency of ISO Committee members... I simply look and laugh at them for what they are doing with this once beautiful language.
To be fair though, some of these 'default's were inherited from C - as when C++ was introduced it was decided that C++ would be as compatible with C as possible to encourage C++ to be used. Hence the name C++!
it was decided that C++ would be as compatible with C as possible to encourage C++ to be used
Yes, I am aware of that. The irk with C++ I have is that the tradition of blissful arrogance continues and instead of fixing things and improving, the ISO Committee simply marks things as UB as they patt each other on their shoulders for "job well done".
Is C++ now a 'camel'?
https://en.wiktionary.org/wiki/a_camel_is_a_horse_designed_by_a_committee
Three legged...
20 Smaller yet Handy C++20 Features - C++ Stories
C++20 is huge and filled with lots of large features. Just to mention a few: Modules, Coroutines, Concepts, Ranges, Calendar & Timezone, Formatting library. But, as you know, that’s not all. Depending on how we count, C++20 brought around 80 Library features and 70 language changes, so there’s a lot to cover :)
https://www.cppstories.com/2022/20-smaller-cpp20-features/