コンパイル時に、特定の数値を表すことができる最小の符号なし整数型を把握する必要があります。このようなもの...
//////////////////////////////////////////////////////////////////////////
template<size_t Bits>
struct uint_least{};
template<>
struct uint_least<8>{ typedef std::uint8_t type; };
template<>
struct uint_least<16>{ typedef std::uint16_t type; };
//////////////////////////////////////////////////////////////////////////
template<size_t max>
struct uint_least_bits
{
static const size_t value = 14; // just a placeholder
};
//////////////////////////////////////////////////////////////////////////
template<size_t max>
class A
{
typedef typename uint_least<uint_least_bits<max>::value>::type underlying_type;
underlying_type m_X;
};
uint_leastは、少なくともBits大きい最小の符号なし整数型を提供することを目的としており、64までの任意の値(8、16、32、64だけでなく、1、4、13など)でも機能するはずです。
uint_least_bitsを表すために必要な最小ビット数を提供することを目的としていますmax。
- どうすれば実装でき
uint_leastますか? - どうすれば実装でき
uint_least_bitsますか? - 、、およびはどのタイプにする必要
bitsがありますか?答えがテンプレートタイプの場合、無効な入力を防ぐにはどうすればよいですか?minmax
特性の正確な構造は重要ではありません。私が提供したものを自由に廃棄してください。数値を入力して、それを保持できる最小の符号なし整数型を取得する必要があります。