title: Ternary operator and if constexpr
body: <p>I have situations where sometimes based on some <code>bool</code> I want to call 2 <code>constexpr</code> functions that return different types and assign it to <code>auto</code> constant. </p>
  
  <p>Unfortunately ternary operator needs types to be "similar". </p>
  
  <p>I have workaround in the code below but it is quite verbose. Is there a better way?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  constexpr int get_int(){
      return 47;
  }
  
  constexpr std::string_view get_string(){
      return "47";
  }
  
  constexpr bool use_str = false;
  
  constexpr auto get_dispatch(){
      if constexpr(use_str){
          return get_string();
      } else{
          return get_int();
      }
  
  }
  int main()
  {
      // what I want : constexpr auto val =  use_str ? get_string():get_int();
      // what works:
      constexpr auto val = get_dispatch();
      std::cout &lt;&lt; val &lt;&lt; std::endl;
  }
  </code></pre>