Say I have a class that takes a boolean in its constructor and depends on the value of the boolean, if calls different functions.
class MyClass {
MyClass(bool is_second)
{
common_code();
if (!is_second)
first_constructor();
else
second_constructor();
}
};
I am new to C++17 and I am wondering if it is possible to write this logic using template programming and if constexpr
. The api is something like this:
MyClass<> obj_calls_first_const;
MyClass<is_second_tag> obj_calls_second_const;