title: const reference to member of temporary object
body: <p>It is <a href="https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/" rel="noreferrer">known feature</a> of C++ that a const reference extends the life time of the temporary object returned from a function, but is it acceptable to use constant reference to the member of the temporary object returned from the function?</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>#include &lt;string&gt;
  
  std::pair&lt;std::string, int&gt; getPair(int n)
  {
      return {std::to_string(n), n};
  }
  
  int main(int, char*[])
  {
      const int x = 123456;
      const auto&amp; str = getPair(x).first;
      printf("%d = %s\n", x, str.c_str());    
      return 0;
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>123456 = 123456
  </code></pre>