Enums to/from Strings
Any thoughts or pointers on the best way to support rendering and parsing of enumerated constants? Some only need to be printed, as for debug messages. Others need to be parsed as well, such as from a configuration file. I'm thinking the solution should provide for uniform access to the conversion including existing uses such as feeding an enumeration constant to Boost.Format and having it automatically render as the string.
2011/7/22 John M. Dlugosz
Any thoughts or pointers on the best way to support rendering and parsing of enumerated constants? Some only need to be printed, as for debug messages. Others need to be parsed as well, such as from a configuration file.
I'm thinking the solution should provide for uniform access to the conversion including existing uses such as feeding an enumeration constant to Boost.Format and having it automatically render as the string.
There's Boost.Enums (not part of Boost yet) developed by Vicente, but I'm not sure the status. See: http://svn.boost.org/svn/boost/sandbox/enums/libs/enums/doc/html/index.html#...
On 7/22/2011 12:19 AM, TONGARI wrote:
There's Boost.Enums (not part of Boost yet) developed by Vicente, but I'm not sure the status.
See: http://svn.boost.org/svn/boost/sandbox/enums/libs/enums/doc/html/index.html#...
He uses a function named c_str() in his own namespace, overloaded for each enumeration type set up by the library. It doesn't do anything automatically with operator<<, lexical_cast, or Boost.Format. You have to call c_str(e) when you want it. For the time being, I've made a function called to_string, which seems to be a common choice. But what's the best way to make it automatically known to those other features?
participants (2)
-
John M. Dlugosz
-
TONGARI