title: lambda parameter with optional return value
body: <p>I'm trying to write a function like <code>std::for_each</code>, that in addition to the normal usage, can also take a <code>std::function&lt;bool (param)&gt;</code>. A false return value means that I want to break out of the loop. The code below is what I've gotten so far.</p>
  
  <p>The second call to <code>a.visit([&amp;](int) -&gt; void)</code> does not compile when evaluating !visitor(i). Is it possible to make this work or am I barking up the wrong tree?</p>
  
  <p>I'm using MSVC 2010 but want the code to be generally C++11 compatible.</p>
  
  <pre><code>#include &lt;list&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  struct A 
  {
      std::list&lt;int&gt; _lst;
  
      template&lt;typename _F&gt;
      void visit(_F visitor) 
      {
          for(std::list&lt;int&gt;::const_iterator it = _lst.begin(), end = _lst.end() ; it != end ; it++) {
              int i = *it;
              if (std::is_void&lt;decltype(visitor(i))&gt;::value) {
                  visitor(i);
              } else {
                 if (!visitor(i)) { // &lt;----- error C2171: '!' : illegal on operands of type 'void'
                     break;
                 }
              }
          }
      }
  
  };
  
  int main(int argc, char* argv[])
  {
      A a;
      // populate a
      for (int i = 0 ; i &lt; 10 ; i++) { 
          a._lst.push_back(i); 
      }
  
      a.visit([](int i) -&gt; bool {
          std::cout &lt;&lt; i &lt;&lt; std::endl;
          return i &lt; 5;
      });
  
      a.visit([](int i) {
          std::cout &lt;&lt; i &lt;&lt; std::endl;
      });
  }
  </code></pre>