Fixed-length integers (created by using the fixedlength parameter of the integer_t
template with a non-zero value) always use the same amount of memory. They can be noticeably faster than unlimited-length integers, especially when combined with an allocator designed for their allocation pattern. However, they can be less memory-efficient for holding smaller values. They also silently discard the upper bits on any value that is too big for them, which can bite the unwary.
integer_t<8>
has a range of -255 to +255, not -128 to +127 like an int8_t
.integer_t<8>(-255) - 1
and integer_t<8>(255) + 1
will both be zero. However, the sign (on non-zero answers) is preserved, so integer_t<8>(-255) - 2
will be -1.© Copyright Chad Nelson, 2010-2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)