title: can a std::tuple be sorted at compilte-time/run-time depending on its values
body: <p>I am wondering if a <code>constexpr std::tuple</code> can be sorted at compile-time:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  struct A{ T val; }; // a constexpr-enabled class
  
  constexpr auto t = std::make_tuple( A&lt;int&gt;{3}, A&lt;float&gt;{1.f}, A&lt;double&gt;{2.0});
  constexpr auto s = sort(t, [](auto&amp;&amp; v){return v.val; });
  
  static_assert(std::is_same_v&lt;std::tuple&lt;A&lt;float&gt;,
                                          A&lt;double&gt;, 
                                          A&lt;int&gt;&gt;,decltype(s)&gt;, "Wups");
  </code></pre>
  
  <p>Is that possible, which building blocks are needed here (<code>std::sort</code> is <code>constexpr</code>) ?</p>
  
  <p>It is (as far as I know) impossible to do that at run-time, since one cannot determine the type of the sorted tuple at runtime. I cannot see a way also if one would build a type-map of all permutations, the actual permutation is still only known at runtime.</p>
  
  <p>Answer <a href="https://stackoverflow.com/a/46006026/293195">https://stackoverflow.com/a/46006026/293195</a> 
  gives some hints and it should work in compile-time, but how? </p>