ref_map: move code to cpp