You are viewing a single comment's thread. Return to all comments →
Decided to play with MetaProgramming,
template struct constexpr_pow { constexpr static uint64_t value() { return base * constexpr_pow::value(); } };
template struct constexpr_pow { constexpr static uint64_t value() { return 1; } }; static_assert(constexpr_pow<2, 0>::value() == 1, "Failed pow(2,0)"); static_assert(constexpr_pow<2, 1>::value() == 2, "Failed pow(2,1)"); template constexpr uint64_t reversed_binary_value_impl() { return 0; } // 0, 0, [1...] template constexpr uint64_t reversed_binary_value_impl() { return digit * constexpr_pow<2, n>::value() + reversed_binary_value_impl(); } template constexpr uint64_t reversed_binary_value() { return reversed_binary_value_impl<0, digits...>(); } static_assert(reversed_binary_value<0>() == 0, "Failed 0b0"); static_assert(reversed_binary_value<1>() == 1, "Failed 0b1");
Seems like cookies are disabled on this browser, please enable them to open this website
C++ Variadics
You are viewing a single comment's thread. Return to all comments →
Decided to play with MetaProgramming,
template struct constexpr_pow { constexpr static uint64_t value() { return base * constexpr_pow::value(); } };
template struct constexpr_pow { constexpr static uint64_t value() { return 1; } }; static_assert(constexpr_pow<2, 0>::value() == 1, "Failed pow(2,0)"); static_assert(constexpr_pow<2, 1>::value() == 2, "Failed pow(2,1)"); template constexpr uint64_t reversed_binary_value_impl() { return 0; } // 0, 0, [1...] template constexpr uint64_t reversed_binary_value_impl() { return digit * constexpr_pow<2, n>::value() + reversed_binary_value_impl(); } template constexpr uint64_t reversed_binary_value() { return reversed_binary_value_impl<0, digits...>(); } static_assert(reversed_binary_value<0>() == 0, "Failed 0b0"); static_assert(reversed_binary_value<1>() == 1, "Failed 0b1");