[cpp] Use template to cast Dynamic key to int in IntMap. Closes #3355