The “crown jewel” of the post first. I use standard C++ and this macro (gasp!):
// guaranteed no evaluation
// guaranteed zero bytes overhead
// can be placed in any scope
#define DBJ_REMOVE(...) \
static_assert( (noexcept(__VA_ARGS__),true) )
Any number of any legal arguments works. In or out of functions. In or out a namespace.
That is runtime zero cost.
noexcept is compile time affair. And since the result is cast to “nothing” aka
void that compiles to exactly 0 bytes.
Continue reading “C++ modern but non-existent code”
Value Handle to Avoid Implicit Conversions in standard C++
“… C++ is not a bad language per se. It’s just, well kinda suffers from bloat. In the words of Richard E. Gooch, “It seduces the programmer, making it much easier to write bloatware“…”
Continue reading “How to avoid implicit conversion in C++”
“…There are issues such as dynamic memory allocation in C/C++, which is forbidden, under the DO-178B standard, in safety-critical embedded avionics code…”
Before knowing the above, the other day I have developed a handy little template to hold and provide, a plain 2d array, completely on the stack (aka the “matrix”).
It is also fully “compile time capable” with the full static internal presentation.
It is very handy to gently enforce company-wide C++ policies and to give some useful functionality in return. I am calling this approach “almost a pod”. Continue reading “Simple matrix for the rest of us”
Interface inheritance is good.
Just stumbled upon this excellent and succinct short text on how not to use inheritance. In C++ in particular, and I am adding: in general.
The purpose of inheritance in C++ is to express interface compliance (subtyping), not to get code reuse.
That text is precisely about differences v.s. the Objective-C, but it is priceless if and when you spot the growth of the weed of inheritance. Continue reading “C++ Inheritance easily grows out of control”
As I am also claiming since ages ago, inheritance as (class or component) composition method is evil. There is no reason to use class inheritance.
And I am not the inventor of this advice.
What more can we say? Ah yes, please read this little text first. Immediately. Then come back here.
Continue reading “C++ Inheritance is Anti-Pattern”