
Oh no, I put it in the sandbox. I should have fixed it locally, as we are in a review. My bad. I am sorry if this is wrong. John, a merge with your checked out copy will be needed.
No problem, it merged OK, however it does fail some of the tests (incorrect conceptual assumptions)... testing a fix now, John.
I re-wrote the assignment to one about ten different ways and the
disturbed tests fail on all re-writes. The solution must go deeper. John, did your fix work? Thanks, Chris.
Oh, I finally noticed that the my proposed pow_imp() function is in the abstraction layer that can only call the "eval_"-style functions. My assignment to the value of 1 would potentially need an "eval_set()" to avoid ambiguous resolution. The workaround below does pass the tests. In order to set the result of the pow:imp() to one, however, I first multiply with zero to clear the result, and subsequently add 1 to get 1---roundabout at best. Do we need an eval_set() that is callable from the "detail" layer? Thanks, Chris. ----------------- Bad WORKAROUND ----------------------------- namespace detail{ template<typename T, typename U> inline void pow_imp(T& result, const T& t, const U& p, const mpl::false_&) { // Compute the pure power of typename T t^p. // Use the S-and-X binary method, as described in // D. E. Knuth, "The Art of Computer Programming", Vol. 2, // Section 4.6.3 . The resulting computational complexity // is order log2[abs(p)]. U p2(p); // Determine if p is even or odd. const bool p_is_odd = (U(p2 % 2) != U(0)); if(p_is_odd) { result = t; } else { eval_multiply(result, 0LL); eval_add(result, 1LL); } // The variable x stores the binary powers of t. T x(t); while(U(p2 /= 2) != U(0)) { // Square x for each binary power. eval_multiply(x, x); const bool has_binary_power = (U(p2 % U(2)) != U(0)); if(has_binary_power) { // Multiply the result with each binary power contained in the exponent. eval_multiply(result, x); } } } ... }