Есть ли какой-либо способ в С++ определить тип, который достаточно велик, чтобы содержать не более определенного числа, предположительно используя какой-то умный код шаблона. Например, я хочу иметь возможность писать: -
Integer<10000>::type dataItem;
И разрешите ли этот тип самому маленькому типу, который достаточно велик, чтобы удерживать указанное значение?
Фон: мне нужно сгенерировать некоторые переменные с использованием script из внешнего файла данных. Я думаю, я мог бы сделать script посмотреть на значения, а затем использовать uint8_t
, uint16_t
, uint32_t
и т.д. В зависимости от значения, но кажется более элегантным построить размер в сгенерированном С++-коде.
Я не вижу способа сделать шаблон, который может это сделать, но, зная шаблоны С++, я уверен, что есть способ. Любые идеи?