Suppose I have a class like
class Empty{ Empty(int a){ cout << a; } }
And then I call it with
int main(){ Empty(2); return 0; }
Will there be a reason for allocating any memory on the stack to create an "empty" object? Obviously, the arguments must be pushed onto the stack, but I don't want to take the extra overhead. I mainly use the constructor as a static member.
I want to do this because of the patterns. Actual code looks like
template <int which> class FuncName{ template <class T> FuncName(const T &value){ if(which == 1){
which allows me to write something like
int main(){ int a = 1; FuncName<1>(a); }
so that I can specialize in one parameter of the template without specifying type T In addition, I hope that the compiler will optimize other branches inside the constructor. If anyone knows if this is true or how to check, that would be greatly appreciated. I also suggested that throwing patterns into a situation does not change the "empty class" problem from above, is this true?
c ++ micro-optimization templates metaprogramming
Victor Liu Jan 06 2018-10-06T00: 00Z
source share