检测是否设置了一个位(在编译时)

The*_* do 3 c++ compile-time

如何检测位置n的位是否设置为常量变量?

ild*_*arn 6

template<std::uint64_t N, std::uint8_t Bit>
struct is_bit_set
{
    static bool const value = !!(N & 1u << Bit);
};
Run Code Online (Sandbox Code Playgroud)

!!用于简洁地将值强制转换为a bool并避免数据截断编译器警告.