Refractor the code and detect the bin content data type at histogram initialization. Based on the bin content data type, the fill method implementation is choosen.