+namespace MapUtilsInternal {
+
+/* This must be hidden in the internal namespace to avoid interfering with
+other things. There may be problems if a key type has operator<< for ostream
+but not LexicalConverter. */
+template<typename T>
+void operator<<(LexicalConverter &, const T &)
+{ }
+
+template<typename T>
+static std::string stringify_key(const T &k)
+{
+ try
+ {
+ LexicalConverter conv((Fmt()));
+ conv<<k;
+ return conv.get();
+ }
+ catch(const lexical_error &)
+ {
+ return "<cannot display value>";
+ }
+}
+
+} // namespace Internal
+