title: Using boost::optional to make optional std::function arguments
body: <p>I have a method which takes four optional callbacks. I want to be able to use lambdas as the callbacks, but I since these callbacks are optional and need a default value, I thought I'd use boost::optional.</p>
  
  <p>Here's a direct copy-paste from my code:</p>
  
  <pre><code>typedef std::function&lt;bool(const GameObjectRef &amp;a, const GameObjectRef &amp;b, cpArbiter *arbiter)&gt; EarlyCollisionCallback;
  typedef std::function&lt;void(const GameObjectRef &amp;a, const GameObjectRef &amp;b, cpArbiter *arbiter)&gt; LateCollisionCallback;
  typedef boost::optional&lt;EarlyCollisionCallback&gt; NullableEarlyCollisionCallback;
  typedef boost::optional&lt;LateCollisionCallback&gt; NullableLateCollisionCallback;
  
  virtual void addCollisionMonitor(cpCollisionType a, cpCollisionType b,
                                  NullableEarlyCollisionCallback onCollisionBegin = boost::none,
                                  NullableEarlyCollisionCallback onCollisionPreSolve = boost::none,
                                  NullableLateCollisionCallback onCollisionPostSolve = boost::none,
                                  NullableLateCollisionCallback onCollisionSeparate = boost::none);
  </code></pre>
  
  <p>The idea is that later I could pass a lambda as callback for, say, the "preSolve" pass of the physics engine and ignore the other optional parameters. This may be bad design, I will likely write this differently. But the real question here is a c++ one. When I try to <em>call</em> this, I get compiler errors at the call site:</p>
  
  <pre><code>addCollisionMonitor(CollisionType::ENEMY, CollisionType::PLAYER,
                      //onCollisionBegin
                      [](const GameObjectRef &amp;enemy, const GameObjectRef &amp;player, cpArbiter *arb)-&gt;bool{
                              CI_LOG_D("Enemy: " &lt;&lt; enemy-&gt;getName() &lt;&lt; " contact player: " &lt;&lt; player-&gt;getName());
                              return true;
                          });
  </code></pre>
  
  <blockquote>
    <p>No viable conversion from '(lambda at /Users/..../GameLevel.cpp:249:8)' to 'NullableEarlyCollisionCallback' (aka 'optional &amp;, const shared_ptr &amp;, cpArbiter *)> >')</p>
  </blockquote>
  
  <p>However, if I explicitly wrap the lambda in NullableEarlyCollisionCallback() it works:</p>
  
  <pre><code>addCollisionMonitor(CollisionType::ENEMY, CollisionType::PLAYER,
                          //onCollisionBegin
                          NullableEarlyCollisionCallback([](const GameObjectRef &amp;enemy, const GameObjectRef &amp;player, cpArbiter *arb)-&gt;bool{
                              CI_LOG_D("Enemy: " &lt;&lt; enemy-&gt;getName() &lt;&lt; " contact player: " &lt;&lt; player-&gt;getName());
                              return true;
                          }));
  </code></pre>
  
  <p>I'm curious why in this instance the compiler can't just convert the lambda to the optional&lt;> type. What am I missing?</p>
  
  <p>This is using Xcode 9 beta3.</p>