title: Using a temporary to initialize multiple members
body: <p>In older C++98, I don't believe there was any good way to reuse a temporary result in an initializer list to initialize multiple members of an object.</p>
  
  <p>Has this changed at all in newer versions of C++ (11, 14, 17)?</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>//
  // compileShaders()
  //
  // Takes a string containing the source code to possibly hundreds of shaders 
  // for an effect (In this case, there are only 2 shaders for this effect)
  //
  // Returns a vector of compiled bytecode for each shader in the effect
  //
  std::vector&lt;std::string&gt; compileShaders(
      const std::string&amp; sourceCode, 
      const RenderTargetLayout&amp; layout);
  
  //
  // class ScaleDownEffect
  //
  // Scales image to 1/4 in each dimension by using two 1/2 passes
  //
  class ScaleDownEffect
  {
  public:
      ScaleDownEffect(const TargetImage&amp; targetImage)
          :   m_renderTarget(targetImage),
  
              m_firstPassShader(      
                  compileShaders(
                      ScaleDownEffectShaderSource, 
                      m_renderTarget.getLayout()
                      )[0], 
                  m_renderTarget.getWidth()  / 2, 
                  m_renderTarget.getHeight() / 2
                  ),
  
              m_secondPassShader(     
                  compileShaders(
                      ScaleDownEffectShaderSource, 
                      m_renderTarget.getLayout()
                      )[1], 
                  m_renderTarget.getWidth()  / 4, 
                  m_renderTarget.getHeight() / 4
                  )
      {
      }
  
  private:
      RenderTarget m_renderTarget;
      Shader m_firstPassShader;
      Shader m_secondPassShader;
  };
  </code></pre>
  
  <p><code>compileShaders()</code> is a very heavyweight call, and I don't really think it's a good idea to call it twice when I don't really have to.</p>
  
  <p><strong>Note</strong> None of the three objects being initialized have default ctors, so doing it in the body of the function is not really an option.</p>
  
  <p>What do we think? Is there any good way for me to do this, or should I switch to smart pointers and dynamically allocate the objects I contain?</p>