I’ve been using types from cstdint (such as uint32_t) in my code regularly, but now they don’t quite fit my needs, particularly with regards to templates.
Is there a way to specify an integer type that is twice the size of a template argument? When my template is passed a uint32_t, I need it to create a uint64_t for one variable within the function. Perhaps more difficultly, when passed a uint64_t, I need it to create a ‘uint128_t’. I could do this with an array of two of the template arguments, but then I can’t pass that array to other template functions. This is a performance critical section of code (I’m doing cryptography).
Related to that, is there some other header I can include (in order of preference: standard, boost, other) that gives me 128-bit integers? Looks like this question answers this particular part: Fastest 128 bit integer library
Is there a way to specify that I want to use the largest integer available that is not greater than a specific size? This maximum size would also be a function of sizeof (T).
“Extended arithmetic” is a shortcoming of the C family of languages. There is no way to obtain the processor’s integer overflow flag, so there is no portable way to write an optimal 128-bit integer class.
For best performance (to compete with other crypto libraries), you might need a static library with custom assembly inside. Unfortunately, I don’t know of a portable (widely-ported) interface to such.
If you just want a map from each fundamental type with N bits to that with 2N bits, then make a simple metafunction: