Stunt programming. Modern C++ is not about that.

User Manual

Here is a short user manual on how to use "dbj  defval" Option 2.2 and Option 3.

First please recall the top of this article. We are using GDI+ to add some dose of reality to these usage examples. And the dose of legacy code issues.

How to use Option 2.2

Declared by me as “probably a stunt” but of course, perfectly usable.

You declare and define inside some namespace the global instances; after which callers from possible separate threads can use. Or change. I am sure you know how to make that “resilient in the presence of threads”.

How to use Option 3

note: c++ anonymous namespaces make variables inside them have internal linkage. I very rarely use them. Please do use named name space’s around these examples.

You declare and define  dbj::holder<> instances as (c++17) inline globals. Then every caller from some thread uses them.  Please keep in mind calls above could be scattered across a few threads, but that would make the code longer and will obfuscate the usage pattern.

I hope you find this post useful and not difficult to grasp. Of course, there are many other solutions but the message is a simple one:

Simplicity rules


So little C++ so much good!
So little C++ so much good!