Change boolean flags into template arguments
Suppose I have a versatile function with about four boolean flags: int do_something(int arg, bool flag1, bool flag2, bool flag3, bool flag4) { for(int i = 0; i < 1000000; i++) { if(flag1) // Do something 1 if(flag2) // Do something 2 if(flag3) // Do something 3 if(flag4) // Do something 4 //Do something else 5 } } But I don't want to incur any costs for branching on these flags in the inner loop so I change them to templates (allowing the compiler to optimize away the conditionals): template<bool flag1, bool flag2, bool flag3, bool flag4> int do_something_helper(int arg) { for(int i = 0; i <