Revert "Revert "[cpp] Keep separate key map to ensure that references are held.  Fix toString""

This reverts commit 75d5929901f86e6acb877b3ba1d25e825234c590.