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”

C++ How to simply handle variable number of function arguments

This is the first of posts, I am going to write primarily for C++ beginners.  Where this title “beginner” is a misnomer in the context of C++. To become a solid C++ beginner takes time and effort.

This is not a good situation. And the reason why, among other reasons, C++ creator (Bjarne Stroustrup) has written very short but, I think a very important “message to all” called  “Remember the Vasa!“. Please read it. Continue reading “C++ How to simply handle variable number of function arguments”