Collection iteration is perhaps the most insidious language construct. Simple to create and easy to understand. Yet lurking within lies the ability to create random non-local defects. Monstrous bugs that you’ll spend […]
Safely using enable_shared_from_this
Obtaining a ‘shared_ptr’ from ‘this’ is possible using the ‘enable_shared_from_this’ class. It’s a feature that allows a class to reference itself within a smart pointer based API. Beware an ugly implementation detail […]
Cannot create a proper clone method with shared_ptr
Smart pointers in C++ are nice, yet fraught with irregularities. One is the inability to create a proper clone function. This requires a feature called covariant return types, which C++ supports, but […]
Overloading the broken universal reference ‘T&&’
C++11 introduced a perfect forwarding mechanism for template parameters. The key part is the ability for a template parameter to match any input without any implicit conversion. This is done using the […]
How to catch a “return” statement
Does ‘return’ always cause a function to return? Surprisingly the answer is “no”. Indeed there are situations in which ‘break’ may not always break from a loop, and ‘goto’ may no go […]
1/2 Should Not Equal Zero
There’s something wrong when a language allows 1/2 to equal 0. It’s easy to understand why this happens, and perhaps it’s even easy to forgive the limitations of C. Nonetheless it’s irksome […]
Leaf: Simple type conversions
One of the problems with C++ is the way it handles type conversion. It inherits a lot of implicit conversion from C and then adds on additional conversions. The problem with all […]
Dangerous and confusing casting
Casting in C++ is a confusing jumble of unclear and dangerous operations. It mixes unrelated concepts. It introduces ambiguities and redundancies. It’s an essential but flawed aspect of the language.
Mismatched Allocation and Delete Nonsense
Efficient yet confused. Powerful but unsafe. So is the nature of C++ object allocation and instantiation.
Implicit Type Promotion and Conversion
C introduced it and C++ mastered it. The hellish world of implicit conversion and type promotion. A system which silently modifies, truncates, rounds, and otherwise mangles our variables.