#pragma once #include #include #ifdef _MSC_VER #include #endif namespace std20 { // A simple (and not very correct) implementation of C++20's std::log2p1 template constexpr T log2p1(T x) noexcept { static_assert(std::is_integral_v && std::is_unsigned_v); if (x == 0) return 0; #ifdef _MSC_VER unsigned long index = 0; _BitScanReverse64(&index, x); return static_cast(index) + 1; #else return static_cast(std::numeric_limits::digits - __builtin_clzll(x)); #endif } } // namespace std20