C++ Bit shift whole array (left) For an embedded project I want to shift a (byte) array left by a certain amount of bits. I've built this template function to do so:

template &lt;typename T&gt;
constexpr void shift_array_left(T *arr, const size_t size, const size_t bits, const bool zero = false) {
    const size_t chunks = bits / (8 * sizeof(T));

    if (chunks &gt;= size) {
        if (zero) {
            memset(arr, 0, size);
        }
        return;
    }

    if (chunks) {
        memmove(arr, arr + chunks, size - chunks);
        if (zero) {
            memset(arr + size - chunks, 0, chunks);
        }
    }

    const size_t left = bits % (8 * sizeof(T));

    // If we have non directly addressable bits left we need to move the whole thing one by one.
    if (left) {
        const size_t right = (8 * sizeof(T)) - left;
        const size_t l = size - chunks - 1;
        for (size_t i = 0; i &lt; l; i++) {
            arr[i] = ((arr[i] &lt;&lt; left) &amp; ~left) | (arr[i+1] &gt;&gt; right);
        }
        arr[l] = (arr[l] &lt;&lt; left) &amp; ~left;
    }
}


Some questions I have:


I inferred from the memmove and memcpy relationships that memmove doesn't guarantee zeroing out any 'gap' created. Can I do away with the zeroing parts?
This function only makes sense for unsigned integer types, what is the best way to force the compiler to only accept these, without repeating function bodies?


I'd, of course, appreciate any further feedback / criticism.

Update: Live example in compiler explorer: https://godbolt.org/g/I3qDsL
For the second question you can use type_traits(is_unsigned) and enable_if.
http://en.cppreference.com/w/cpp/types/is_unsigned
http://en.cppreference.com/w/cpp/types/enable_if

For the first question:
The main difference between memmove and memcpy is that memmove can be used to relocate a piece of memory to somewhere that overlaps the memory block that you're trying to move. And therefore the original pointer will no longer be valid. So I think it's up to you how you want your function to behave, if you want the parts to be zeroed or not or leave it too the user.