title: std::ratio power of a std::ratio at compile-time?
body: <p>I have a challenging question from a mathematical, algorithmic and metaprogramming recursion point of view. Consider the following declaration:</p>
  
  <pre><code>template&lt;class R1, class R2&gt;
  using ratio_power = /* to be defined */;
  </code></pre>
  
  <p>based on the example of the <a href="http://en.cppreference.com/w/cpp/numeric/ratio/ratio" rel="noreferrer"><code>std::ratio</code></a> operations like <a href="http://en.cppreference.com/w/cpp/numeric/ratio/ratio_add" rel="noreferrer"><code>std::ratio_add</code></a>. Given, two <code>std::ratio</code> <code>R1</code> and <code>R2</code> this operation should compute <code>R1^R2</code> if and only if <code>R1^R2</code> is a rational number. If it is irrational, then the implementation should fail, like when one try to multiply two very big ratios and the compiler say that there is an integer overflow.</p>
  
  <p>Three questions:</p>
  
  <ol>
  <li>Do you think this is possible without exploding the compilation
  time? </li>
  <li>What algorithm to use? </li>
  <li>How to implement this operation?</li>
  </ol>