title: Deducing constness of type returned by function
body: <p>Is there a way to tell whether a function returns a const or a non-const value? <code>decltype</code> works for references, but it won't work for non-reference types.</p>
  
  <pre><code>#include &lt;type_traits&gt;
  
  template&lt; typename &gt;
  struct print_type;      //undefined
  
  int main(){
    auto lambda = []()-&gt;const int{ return 0; };
    print_type&lt; decltype(lambda()) &gt; dt;   //print_type&lt; int &gt;
    print_type&lt; typename std::result_of&lt;decltype(lambda)()&gt;::type &gt; ro;  
      //print_type&lt; int &gt;
  
  
    return 0;
  }
  </code></pre>
  
  <p>I implemented a <code>std::tuple</code> transform function, that will call a function object on each tuple element and store the result in a new <code>tuple</code> composed of return types. This doesn't work for const return types, which is pretty surprising (but needed).</p>