title: C/C++ macro/template blackmagic to generate unique name
body: <p>Macros are fine.
  Templates are fine.
  Pretty much whatever it works is fine.</p>
  
  <p>The example is OpenGL; but the technique is C++ specific and relies on no knowledge of OpenGL.</p>
  
  <p>Precise problem:</p>
  
  <p>I want an expression E; where I do not have to specify a unique name; such that a constructor is called where E is defined, and a destructor is called where the block E is in ends.</p>
  
  <p>For example, consider:</p>
  
  <pre><code>class GlTranslate {
    GLTranslate(float x, float y, float z); {
      glPushMatrix();
      glTranslatef(x, y, z);
    }
    ~GlTranslate() { glPopMatrix(); }
  };
  </code></pre>
  
  <p>Manual solution:</p>
  
  <pre><code>{
    GlTranslate foo(1.0, 0.0, 0.0); // I had to give it a name
    .....
  } // auto popmatrix
  </code></pre>
  
  <p>Now, I have this not only for glTranslate, but lots of other PushAttrib/PopAttrib calls too. I would prefer not to have to come up with a unique name for each var. Is there some trick involving macros templates ... or something else that will automatically create a variable who's constructor is called at point of definition; and destructor called at end of block?</p>
  
  <p>Thanks!</p>