
Affective C++
@affectivecpp
The authoritative guide for High Quality C++!
(Warning: These are all jokes.)
ID: 1041950022978465794
18-09-2018 07:20:18
299 Tweet
3,3K Takipçi
72 Takip Edilen

🇺🇦 Björn @[email protected] 😷💉⁴ Affective C++ The other advantage is that it forces you to keep the number of local variables down to a manageable 26 or less.

Item 73: If you experience seemingly random crashes and bugs in your software, simply ship it with -O0 to reduce the failure rate. (Thanks Corentin Brunel) #cplusplus #cpp #affectivecpp


Item 74: std::vector<bool> is widely regarded as a bad idea. Instead, prefer using std::basic_string<bool>, which both behaves as an actual container, avoids proxy objects, and gives you a small vector optimization for free! (Thanks Martin Hořeňovský) #cplusplus #cpp #affectivecpp

Item 75: For owning pointers, use `int *variable` (star next to the variable you own), and for non-owning pointers use `int* variable` (star away from the variable) (Thanks Ólafur Waage) #cplusplus #cpp #affectivecpp


Item 76: Can't remember all the different casts? Replace them all by the more powerful unicorn_cast: template <typename T, typename U> T unicorn_cast(U&& u) { void* addr = &u; return *static_cast<T*>(addr); } (Thanks 🇺🇦 Björn @[email protected] 😷💉⁴) #cplusplus #cpp #affectivecpp

Victor Ciura Pro-tip: Commas are quicker to parse than semi-colons because there are less pixels in the character. Affective C++

Affective C++ this is how the professionals structure projects.


Item 77: The difference between char and wchar_t is that char is for narrow characters, and wchar_t is for wide characters. Store letters like i and j in a char, and letters like m and w in a wchar_t. (Thanks Chris Oldwood) #cplusplus #cpp #affectivecpp

David Stone But `unsigned const int` is not the same as `const unsigned int` nor `unsigned int const`. For east-const builds unsigned const int makes the high bit read-only. For west-const builds it makes everything *except* the high bit read-only. We rejected central due to the ambiguity.

Item 79: Choosing the right data structure is critical. Is memset too slow? Consider memunordered_set instead, to avoid the red-black tree in favor of hashing. See also memmap for key/value, mempriority_queue, memstack, etc. (thanks JF Bastien) #cplusplus #cpp #affectivecpp