C++ How to make unwanted code visible but non-existent

C++ How to make unwanted code visible but non-existent?  Huh, what is “non-existent”?  That is: it is compiled into zero bytes. It is non-existent in the resulting executable.

Ok, but, you might want it back sometime in the near future?  Well, that is simple, say you, there is this well known, mature and universally used macro that does make unused code “get out of the way”

// de-facto standard
#define UNUSED(x) (void)x

If this macro makes you ask questions please read on, otherwise, leave in peace. Continue reading “C++ How to make unwanted code visible but non-existent”

Never underestimate Generic Lambda in Modern C++

Generic Lambda

This is an update of my previous post. With a moral to the story too.  I might hope some C++ beginner might learn something useful here too.

[On-line source code is here]

 

Having my usual morning workout in the brain gym called cppreference.com, I noticed a comment inside the example snippet on the page  about std::apply

Continue reading “Never underestimate Generic Lambda in Modern C++”

c++ How to implement self referencing type

Drawing Hands is a lithograph by the Dutch artist M. C. Escher
Drawing Hands is a lithograph by the Dutch artist M. C. Escher

What is it? A type (struct or class) whose instance contains one or more references to the instance of the same type.

A sketch:

// Self Referencing type
struct SR { 

   char state;
const SR & ref;

};

Why would anybody do this? Continue reading “c++ How to implement self referencing type”