1. #include <cstdio>
  2. #include <cstdlib>
  3.  
  4. class CThing
  5. {
  6. private:
  7.     int m_iVar;
  8.  
  9. public:
  10.     CThing(int iInput = 0)
  11.     : m_iVar(iInput)
  12.     {
  13.     }
  14.  
  15.     // Branchy code
  16.     void Process(bool bIncrementAfter)
  17.     {
  18.         printf("%d\n", m_iVar);
  19.         if (bIncrementAfter)
  20.             ++m_iVar;
  21.     }
  22.  
  23.     // Branchless code
  24.     template <bool t_bIncrementAfter>
  25.     void Process()
  26.     {
  27.         printf("%d\n", m_iVar);
  28.         if (t_bIncrementAfter)
  29.             ++m_iVar;
  30.     }
  31.  
  32.     int GetVar() const { return m_iVar; }
  33. };
  34.  
  35. void main()
  36. {
  37.     CThing a(10);
  38.  
  39.     a.Process((rand() % 2) == 1); // Using rand() to force compiler to support both true and false
  40.     a.Process<true>();
  41.     printf("%d\n", a.GetVar());
  42. }