title: How can I determine the return type of a C++11 member function
body: <p>I am trying to determine the return type of a various C++ member functions. I understand that decltype and std::declval can be used to do this, but I am having problems with the syntax and finding useful examples. The <code>TestCBClass</code> below shows an example of a dumb class that contains a mixture static and normal member functions - with &amp; without arguments and return types.  Depending on the method in question, I would like to be able to declare a vector of return types from each of the various methods.  </p>
  
  <p>In my application, these methods are callbacks for <code>std::async</code> and I need a vector of <code>std::future&lt;return types&gt;</code>.  I've tried various declarations such as <code>decltype(std::declval(TestCBClass::testStaticMethod))</code> (I'm not sure if I need an <code>&amp;</code> before the method name).   This syntax is incorrect - and of course it does not compile, but I think its the approach that should be used.</p>
  
  <pre><code>class TestCBClass {
  public:
      TestCBClass(const int&amp; rValue = 1)
          : mValue(rValue) {
          std::cout &lt;&lt; "~TestCBClass()" &lt;&lt; std::endl;
      }
      virtual ~TestCBClass() {
          std::cout &lt;&lt; "~TestCBClass()" &lt;&lt; std::endl;
      }
      void testCBEmpty(void) {
          std::cout &lt;&lt; "testCBEmpty()" &lt;&lt; std::endl;
      }
      int testCBArgRet(const int&amp; rArg) {
          std::cout &lt;&lt; "testCBArgRet(" &lt;&lt; rArg &lt;&lt; ")" &lt;&lt; std::endl;
          mValue = rArg;
      }
      static void testCBEmptyStatic(void) {
          std::cout &lt;&lt; "testCBEmptyStatic()" &lt;&lt; std::endl;
      }
      static void cbArgRetStatic(const SLDBConfigParams&amp; rParams) {
          std::lock_guard&lt;std::mutex&gt; lock(gMutexGuard);
          std::cout &lt;&lt; rParams.mPriority &lt;&lt; std::endl;
      }
      static std::string testStaticMethod(const PriorityLevel&amp; rPrty) {
          return "this is a silly return string";
      }
  private:
      int mValue;
  };
  </code></pre>