Initializing multiple references with std::tie
<p>I'd like to have a neat way of initializing multiple references returned from a function via <code>std::tuple</code> using <code>std::tie</code> (or <code>std::forward_as_tuple</code>)—see toy code below.</p>

<pre><code>#include &lt;tuple&gt;
#include &lt;iostream&gt;

class Foo
{
public:
    Foo () : m_memberInt(5), m_anotherMemberInt(7) {}

    void IncrementMembers() {++m_memberInt; ++m_anotherMemberInt;}

    std::tuple&lt;int &amp;, int &amp;&gt; GetMembers() {return std::tie(m_memberInt, m_anotherMemberInt);}

private:
    int m_memberInt;
    int m_anotherMemberInt;
};

int main()
{
    Foo foo;

    // Can't have dangling references.
    // int &amp;x, &amp;y;
    // std::tie(x, y) = foo.GetMembers();

    std::tuple&lt;int &amp;, int &amp;&gt; tmpTuple = foo.GetMembers();
    int &amp;x = std::get&lt;0&gt;(tmpTuple);
    int &amp;y = std::get&lt;1&gt;(tmpTuple);

    std::cout &lt;&lt; x &lt;&lt; " " &lt;&lt; y &lt;&lt; std::endl;

    foo.IncrementMembers();
    std::cout &lt;&lt; x &lt;&lt; " " &lt;&lt; y &lt;&lt; std::endl;

    return 0;
 }
</code></pre>

<p>The solution above works but having the temporary <code>std::tuple</code> and multiple <code>std::get</code>s is annoying and it would be great to be able to avoid this if possible (like when returning non-references).</p>

<p>The issue is that we can't have dangling references so can't initialize the variables beforehand. Is there some C++11/C++14 wizardry to allow me to initialize references as I call <code>std::tie</code>? Or is the above the only solution?</p>