Is it worth considering an alternative to boost::format() here? From what I recall it's not particularly quick, and this change is mostly about performance. Or do you think the fact that it only happens once per unique value negates any performance problem?