title: C++ Returning Type Deduction Failing
body: <p>The return type on the fmap function does not auto deduce to be the right type of Option</p>
  
  <p>Can anyone help?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  template&lt;class T&gt;
  class Option{
  public:
      Option() : value_(nullptr){
      }
      Option(T const&amp; value) : value_(std::move(value)){
  
      }
      Option(T&amp;&amp; value) : value_(std::make_shared&lt;T&gt;(std::move(value))){
  
      }
      Option(Option const&amp;) = default;
      Option(Option&amp;&amp;) = default;
      Option&amp; operator = (Option const&amp;) = default;
      Option&amp; operator = (Option&amp;&amp;) = default;
  
      template&lt;class U&gt;
      auto fmap(std::function&lt;U ( T const&amp; ) &gt; func) -&gt; Option&lt;decltype( func(std::declval&lt;T&gt;() ) )&gt;{
          return Option&lt;U&gt;(func(*value_));
      }
  
      template&lt;class U&gt;
      Option&lt;U&gt; operator &gt;&gt;= (std::function&lt;Option&lt;U&gt; ( T const&amp; ) &gt; func){
          if(value_ == nullptr)
              return Option&lt;U&gt;();
          return func(value_);
      }
  
      static Option&lt;T&gt; Unit(T const&amp; value){
          return Option&lt;T&gt;(value);
      }
  
      static Option&lt;T&gt; Unit(T&amp;&amp; value){
          return Option&lt;T&gt;(std::move(value));
      }
  private:
      std::shared_ptr&lt;T&gt; value_;
  };
  
  int main(int argc, const char * argv[])
  {
  
  
      Option&lt;int&gt; o(55);
      auto f = [](int const&amp; i){
          return i + 1;
      };
      auto result = o.fmap&lt;int&gt;(f);
  
  
      return 0;
  }
  </code></pre>