wesnoth/wesnoth — pull request #124 by 8573 (2014-03-21 05:04:44+00:00)
Title: Add `bit_width` functions

Add the following functions in `src/util.hpp`:

template inline std::size_t bit_width();
template inline std::size_t bit_width(T x);

These functions compute the size, in bits, of a type or value, providing
a convenient and self-documenting name for the underlying expression,
`sizeof(…) * std::numeric_limits::digits`.

This commit adds two additional header `#include` directives in
`src/util.hpp`. The newly included headers are as follows:

- ``, for `std::size_t`; and
- ``, for `std::numeric_limits`.

At first, I obtained the bit width of a byte using the C preprocessor
macro `CHAR_BIT`, defined in the C standard library header ``,
rather than using `std::numeric_limits::digits`, but I
subsequently switched to using `std::numeric_limits` per Soliton’s
recommendation at 2014-03-17 21:36Z in the `#wesnoth-dev` IRC channel on
the freenode IRC network ().