title: How to handle void decltype();
body: <p>I'd like to create a template that calls a member function on another object that returns the same type as the member function.  The syntax for using decltype on the member function is a bit ugly, but it seems to work in every case except one.</p>
  
  <p>Here's the call:</p>
  
  <pre><code>struct container: map&lt;string, C&gt; 
  {
      template&lt; typename MemFnPtrType, typename... _ArgTypes&gt;
      auto safeOperation(string key, MemFnPtrType mfp, _ArgTypes&amp;&amp;... args )
          -&gt; decltype( (((C*)nullptr)-&gt;*mfp)(args...))
      {
          C* pC = NULL;
          decltype((pC-&gt;*mfp)(args...)) result;
  
          iterator it = find(key);
          if (it != end())
          {
              C* pC = &amp;(it-&gt;second);
              result = (pC-&gt;*mfp)(args...);
              cout &lt;&lt; "result:" &lt;&lt; result &lt;&lt; "\n";
          }
          else
          {
              cout &lt;&lt; "key: " &lt;&lt; key &lt;&lt; " missing\n";
          }
          return result;
      }
  };
  </code></pre>
  
  <p>This works fine until the member function returns void.</p>
  
  <p>Is there a way to detect this and leave out the offending lines?</p>
  
  <p>I could obviously create a voidSafeOperation function.  I don't mind creating another template, but I'd like to use the same name "safeOperation" so the call sites don't need to use different helpers based on the return type of the member function.  </p>
  
  <p>Thanks!</p>
  
  <p>Full Example: 
  <a href="http://cpp.sh/7ft" rel="nofollow">http://cpp.sh/7ft</a></p>