title: How to use std::invoke_result_t to get return type of a function
body: <p>I'm trying to implement a flavored <code>for_each()</code>, it will stop iteration when the passed in function returns <code>false</code>. If the passed in function doesn't return a Boolean value, then run through as <code>std::for_each()</code>.</p>
  
  <p>I'm having some difficulty getting the returned type of function parameter, I tried to use <code>std::invoke_result_t</code>, but it complains:</p>
  
  <blockquote>
    <p>no member named 'type' in 'std::__1::invoke_result&lt;...</p>
  </blockquote>
  
  <p>In the <a href="https://en.cppreference.com/w/cpp/types/result_of" rel="nofollow noreferrer">example</a> on C++ reference, it always passes in the <code>Arg</code> type for the function. But in my case, shouldn't type <code>F</code> already contain all the type information of the whole function?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;class C, class F&gt;
  void for_each(C container, F&amp;&amp; f)
  {
      for (auto const&amp; v : container)
      {
          if constexpr (std::is_same_v&lt;std::invoke_result_t&lt;F&gt;, bool&gt;)
          {
              if (not std::forward&lt;F&gt;(f)(v))
                  break;
          }
          else
          {
              std::forward&lt;F&gt;(f)(v);
          }
      }
  }
  </code></pre>