Singleton done right in C++ 11

Today searching the internet I've found a "cool" and simple method to create a safe singleton that performs well in multithreading environment. With a small amount of lines you can achieve both: safe initialization and multithreading safety. class Singleton { static std::once_flag onceFlag; static Singleton* instance; public: static Singleton& getInstance(){ std::call_once(onceFlag, []{ instance = new Singleton(); }); return *instance; } private: Singleton(){}; }   As c++ documentation says the: The class std::once_flag is a helper structure for std::call_once. An object of type std::once_flag that is passed to multiple calls to std::call_once allows those calls to coordinate with each other such that only one of...
Read More

Turbo boost disabler for Mac OSX

Searching a better way to improve battery life when compiling programs without a connected charger I've found Turbo Boost Switcher. This software instructs the CPU to work at it's limited hardware clock and not taking advance of the extra juice offered by the turbo boost technology. While on Linux or Windows this can be achieved very easily using the performance tuner for each Power Profile, on mac this is almost impossible with the onboard tools supplied by apple. Attention while using this tool since it's not an apple supplied software it may lead to unexpected system behaviour. This is highly unlikely to happen, but be careful....
Read More
The PIMPL idiom

The PIMPL idiom

The purpose Remove compilation dependencies on internal class implementations and improve compile times. Brief example // foo.h - header file #include <memory> class foo { public: foo(); ~foo(); foo(foo&&); foo& operator=(foo&&); private: class impl; std::unique_ptr pimpl; }; // foo.cpp - implementation file class foo::impl { public: void do_internal_work() { internal_data = 5; } private: int internal_data = 0; }; foo::foo() : pimpl{std::make_unique()} { pimpl->do_internal_work(); } foo::~foo() = default; foo::foo(foo&&) = default; foo& foo::operator=(foo&&) = default; The story behind the...
Read More
Inheritance in C++

Inheritance in C++

The question: I looked and couldn't find a good explanation of the difference between public, private, and protected inheritance in C++. All of the questions I've found deal with specific cases. What is the difference in general? The answer: There are three accessors that I'm aware of: public, protected and private. Lets take the following example: class Base { public: int publicMember; protected: int protectedMember; private: int privateMember; }; Everything that is aware of Base is also aware that Base contains publicMember. Only the children (and their children) are aware that Base contains protectedMember. No one but Base is aware of privateMember. By is aware of, I mean acknowledge the existence of, and thus be able to access. The same happens with public, private and protected inheritance. Let's consider a class Base and a class Child that inherits...
Read More
GITLab workflow

GITLab workflow

Gitlab Asa cum va povesteam in postarea anterioara anul trecut am avut placuta sansa ca alaturi de colegii de serviciu sa dezbatem subiectul sistemelor de versionare. Folosind zilnic platformele opensource github, gitlab, bitbucket si cunoscand destul de bine subiectul am creat niste prezentari pentru git. Cand vine vorba de utilitare ce vin in ajutorul programatorului pentru dezvoltarea software si decuplarea contextelor, gitlab este un utilitar foarte puternic. Am pregatit o scurta prezentare a acestuia. Bafta la vizionat! GITLab workflow ...
Read More
Branching can change your (programming) life

Branching can change your (programming) life

Branch,context Asa cum va povesteam in postarea anterioara anul trecut am avut placuta sansa ca alaturi de colegii de serviciu sa dezbatem subiectul sistemelor de versionare. Folosind zilnic platformele opensource github, gitlab, bitbucket si cunoscand destul de bine subiectul am creat niste prezentari pentru git. Nu stiu cati dintre voi v-ati pus problema lucrului in echipa, ce inseamna ce presupune si cum ati putea sa va organizati mai bine astfel incat fiecare sa poata sa lucreze linistit la partea lui stiind ca intr-un final lucrurile se vor imbina armonios. Atunci cand lucram in echipa fiecare membru va da nastere unui asa zis context, context care va conduce la lucrul in paralel cu un alt coleg in remedierea unor probleme. Ganditi-va cum ar trebui sa fie organizate task-urile astfel incat cei doi coechipieri sa nu se calce pe picioare. Prezentarea ce urmeaza prezinta niste metode ce sper sa va vina in ajutor in negocierea mult mai buna a unei astfel de situatii. Branching can change your life ...
Read More