array – Do C++ compilers optimize/pack small data types (e.g. boolean values)?

This occurred to me when looking at stencil computations in numpy. This python library compiles compute-intensive components, so I believe that it’s a valid example. Here making selections on an array is done with small offsets (0, 1, -1) a lot of times. Would a c++ compiler take into account that it doesn’t need a full integer/char/bool type and “pack” bits into bytes?

For example, could selecting every second element from 0 to 7, be represented as a single byte instead of 8 bytes:

0,1,0,1,0,1,0,1

instead of

0,0,0,0,0,0,0,0

0,0,0,0,0,0,0,1

0,0,0,0,0,0,0,0

0,0,0,0,0,0,0,1

0,0,0,0,0,0,0,0

0,0,0,0,0,0,0,1

0,0,0,0,0,0,0,0

0,0,0,0,0,0,0,1