title: different types in operator ? with no-capture, same signature, lambda
body: <p>According to the c++ standard, a lambda function has a unique type, hence in general two lambdas cannot be used in conjunction with the <code>?</code> operator. However, as discussed in <a href="https://stackoverflow.com/questions/41121441/type-of-a-lambda-function-using-auto">this question</a>, a lambda with no capture can be converted to a function pointer. Hence, the following code correctly compiles:</p>
  
  <pre><code>int main()
  {
      bool x = true;
      auto a_lambda = x ? [](int p) { } : [](int p) { };
  }
  </code></pre>
  
  <p>However, if the argument of the lambda is declared <code>auto</code></p>
  
  <pre><code>int main()
  {
      bool x = true;
      auto a_lambda = x ? [](auto p)  { } : [](auto p) { };
  }
  </code></pre>
  
  <p>the code no longer compiles, giving error:</p>
  
  <pre><code>main.cpp:4:23: error: operands to ?: have different types 'main()::&lt;lambda(auto:1)&gt;' and 'main()::&lt;lambda(auto:2)&gt;'
  
      4 |     auto a_lambda = x ? [](auto p)  { } : [](auto p) { };
  </code></pre>
  
  <p>The code also does not compile if I force the assignment to a function with parameter <code>int</code>:</p>
  
  <pre><code>#include &lt;functional&gt;
  
  int main()
  {
      bool x = true;
      // error: operands to ?: have different types 'main()::&lt;lambda(auto:1)&gt;' and 'main()::&lt;lambda(auto:2)&gt;'
      std::function&lt;void(int)&gt; a_lambda = x ? [](auto p)  { } : [](auto p) { };
  }
  </code></pre>
  
  <p>With the assignement to a function with given signature, the <code>auto</code> in the parameter list should be for both lambdas deduced as <code>int</code>.</p>
  
  <ul>
  <li><p>Why have the two lambdas still a different type?</p></li>
  <li><p>Is there a way to fix the second code, i.e., is it possible to "choose" with the <code>?</code> operator between two lambdas that have an <code>auto</code> in the parameter list, if I am sure that for both lambdas the <code>auto</code> will be deduced to the same type?</p></li>
  </ul>