Via Macros
A way to realise different variants is to work with variant flags within the code itself. The big issue is that this can make the code harder to read.
Example
#include feature_1.hpp" #include feature_3.hpp" #if defined(base) || defined(var_1) #include feature_4.hpp" #endif #if defined(base) || defined(var_2) #include feature_2.hpp" #include feature_5.hpp" #endif int main() { auto feature_1 = std::make_shared<Feature_1>(); auto feature_3 = std::make_shared<Feature_3>(); #if defined(base) || defined(var_1) auto feature_4 = std::make_shared<Feature_4>(); #endif #if defined(base) || defined(var_2) auto feature_2 = std::make_shared<Feature_2>(); auto feature_5 = std::make_shared<Feature_5>(); #endif //... return 0; }
Via Branching
Another way is to work with an additional branch bundle (shown here) for each variant. The issue here is that features possible get onto multiple branches.
Example
[base] ---(Feature_1)---(Feature_2)---(Feature_3)---(Feature_4)---(Feature_5) \ \ [var_1] (Feature_3)---(Feature_4) \ \ [var_2] (Feature_5)
At the company I’m working at currently (Head unit supplier for VW) we are using the macro approach to handle different variants. We also use the branching approach, but just for major releases, which has to be really stable at the end. Those releases getting fixes over serveral iterations and therefore get multiple release branches itself.