
Affective C++
@AffectiveCpp
The authoritative guide for High Quality C++! (Warning: These are all jokes.)
You might like
(Just in case someone missed the point: @AffectiveCpp is a humorous account, everything we post is spectacularly wrong.)
On x86, the stack grows “down” towards lower addresses. However, this is only true in the northern hemisphere due to the Coriolis effect. In Australia, the stack grows up actually. That’s because they are all looking at their monitors upside down to avoid falling off the planet.
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 @jfbastien) #cplusplus #cpp #affectivecpp
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 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 @chrisoldwood) #cplusplus #cpp #affectivecpp
The difference between char and wchar_t in C++ is that char is for narrow characters and wchar_t is for wide characters. So you’d store letters like i, l, and t in a char but M and W in a wchar_t…
Pro-tip: Commas are quicker to parse than semi-colons because there are less pixels in the character. @AffectiveCpp
@AffectiveCpp this is how the professionals structure projects.
Top tip: name your directories well: put all of your template metaprogramming code in a directory called "tmp". Preferably /tmp.
programming protip! when you see x >= 0, that's a handy shortcut for x = x > 0
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 @bjorn_fahller) #cplusplus #cpp #affectivecpp
Top tip: name your directories well: put all of your template metaprogramming code in a directory called "tmp". Preferably /tmp.
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 @olafurw) #cplusplus #cpp #affectivecpp
int* variable; For non owning pointers, since the * is far away from your variable (which you own) int *variable; Then for owning pointers. @AffectiveCpp (ps. don't do this, use smart pointers)
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 @horenmar_ctu) #cplusplus #cpp #affectivecpp
As we all know, std::vector<bool> keeps causing endless issues. But did you know you can use std::basic_string<bool> instead, avoiding the terrible proxy objects? You even get a small vector optimization for free. 😈
Item 73: If you experience seemingly random crashes and bugs in your software, simply ship it with -O0 to reduce the failure rate. (Thanks @Cor3ntin) #cplusplus #cpp #affectivecpp
As we all know, std::vector<bool> keeps causing endless issues. But did you know you can use std::basic_string<bool> instead, avoiding the terrible proxy objects? You even get a small vector optimization for free. 😈
The other advantage is that it forces you to keep the number of local variables down to a manageable 26 or less.
United States Trends
- 1. Bills 104K posts
- 2. Falcons 26K posts
- 3. phil 120K posts
- 4. Josh Allen 11.3K posts
- 5. Bijan 15.7K posts
- 6. Drake London 3,762 posts
- 7. McDermott 3,058 posts
- 8. Bears 43.1K posts
- 9. phan 91.3K posts
- 10. #RaiseHail 4,127 posts
- 11. #BUFvsATL 2,416 posts
- 12. Beane 1,437 posts
- 13. Jake Moody 1,731 posts
- 14. Caleb 29.8K posts
- 15. Penix 3,400 posts
- 16. Starship 69.2K posts
- 17. #RiseUp 1,109 posts
- 18. Jayden 10.5K posts
- 19. Columbus 259K posts
- 20. SpaceX 105K posts
You might like
-
Core C++
@corecpp -
Jason Turner
@lefticus -
C++ on Sea
@cpponsea -
Andreas Fertig
@Andreas__Fertig -
Rainer Grimm
@rainer_grimm -
Jonathan Müller
@foonathan -
Daisy Hollman
@The_Whole_Daisy -
Bartlomiej Filipek
@fenbf -
Bryce Adelstein Lelbach
@blelbach -
Barry Revzin
@BarryRevzin -
Vittorio Romeo
@supahvee1234 -
Victor Ciura
@ciura_victor -
Richard Smith
@zygoloid -
Kris Jusiak
@krisjusiak -
CppCon
@CppCon
Something went wrong.
Something went wrong.