title: Are there any mechanisms other than copy elision that can optimize out excessive construction in C++?
body: <p>My function has a switch-case statement. There is an object that is used only in some of its branches. Can I put an initialization of this object before the switch-case statement and expect that it will be created only when it is actually being used.</p>
  <p>By that, I mean, is there any difference in performance between this code:</p>
  <pre><code>void someFunc( SomeEnum someEnum, Parameter parameter )
  {
      Object object( parameter );
      
      switch( someEnum )
      {
      case SomeEnum::A:
          otherFunc( object );
          break;
          
      case SomeEnum::B:
          otherFunc( object );
          break;
          
      case SomeEnum::C:
          anotherFunc();
          break;
      }
  }
  </code></pre>
  <p>And this one:</p>
  <pre><code>void someFunc( SomeEnum someEnum, Parameter parameter )
  {   
      switch( someEnum )
      {
      case SomeEnum::A: {
              Object object( parameter );
              otherFunc( object );
          }
          break;
          
      case SomeEnum::B: {
              Object object( parameter );
              otherFunc( object );
          }
          break;
          
      case SomeEnum::C:
          anotherFunc();
          break;
      }
  }
  </code></pre>