TransferBitmap has two template parameters of bool type with four combinations.
Change them to function parameters can reduce code size. I think "restore_trailing_bits" cannot impact performance. "invert_bits" needs benchmark.
Also, bool parameter is hard to figure out at caller side, better to use meaningful defines.