cpp version of emilio's py code