I've spent a good amount of time in this Industry. Learned how to write good simple program and trying to learn more to reach to intermediate level. Journey was mix of reward and hardwork. Met people with different dimension, different skill set and lately realized I'm not only the person who wants to excel truly by learning the system more and more.
Anyway in few upcomming series, I'll reveal some good approaches which I've learned so far by introspection. Will look more into the digital system and will see how it similar to our daily concepts.
The idea of having a class to add numbers (variable parameters) during compilation time recursively. Also wanted to restrict types to a single type while sending parameters to class member function. That said, if we mix int, float and double types to add function shall result in compilation error. How do we achieve this. The below is the code which actually helps to achieve this: <code> #include < fmt/format.h > template < typename T> class MyVarSumClass{ private : T _sum = 0 ; public : template < typename ... TRest> T add(T num, TRest... nums){ static_assert (std::conjunction<std::is_same<TRest, T>...>{}); /* Assert fails if types are different */ _sum += num; return add(nums...); // Next parameter packs gets picked recursively } // Base case T add(T num){ _sum += num; return _sum; } }; int main() { My
Comments