
It looks nice, but does it also work with other structures than strings? i.e. BOOST_ENUM(id, (ab_device)("device for your abs", /*activation code*/ 13, /*typical % of time used*/ 0.0) (pc_device)("personal computer", /*activation code*/ 42, /*typical % of time used*/ 100.0) ) -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Frank Laub Sent: Wednesday, December 07, 2005 12:47 To: boost@lists.boost.org Subject: [boost] BOOST_ENUM proposal Hello fellow boosters, I've recently come up with a way to use the boost preprocesor to generate a 'better' enum type. The following is an example of some typical usage. Is anyone else interested in this sort of thing? I'm hoping to get suggestions for how to make it more 'boost-like' in both its implementation and its usage. Is this very readable? Is there a place I can upload the code for people to peruse? #include <iostream> #include <boost/enum.hpp> #include <boost/foreach.hpp> #define foreach BOOST_FOREACH BOOST_ENUM(Level, (Abort)("unrecoverable problem") (Error)("recoverable problem") (Alert)("unexpected behavior") (Info)("expected behavior") (Trace)("normal flow of execution") (Debug)("detailed object state listings") ) int main() { foreach(const string& name, Level::names) { cout << name << endl; } cout << "1: " << Level::names[1] << endl; cout << "toString(Abort): " << Level::toString(Level::Abort) << endl; cout << "getValue(Abort): " << Level::getValue(Level::Abort) << endl; Level::type value = Level::Invalid; bool ret = Level::fromString("Abort", value); cout << "fromString(\"Abort\"): " << ret << ", " << value << endl; value = Level::Invalid; ret = Level::fromString("Debug", value); cout << "fromString(\"Debug\"): " << ret << ", " << value << endl; value = Level::Invalid; ret = Level::fromString("not in enum", value); cout << "fromString(\"not in enum\"): " << ret << ", " << value << endl; return 0; } With the program output being: Abort Error Alert Info Trace Debug Invalid 1: Error toString(Abort): Abort getValue(Abort): unrecoverable problem fromString("Abort"): 1, 0 fromString("Debug"): 1, 5 fromString("not in enum"): 0, 6 -Frank _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 12/7/05, Job Mulder <Job@xsens.com> wrote:
It looks nice, but does it also work with other structures than strings? i.e.
BOOST_ENUM(id, (ab_device)("device for your abs", /*activation code*/ 13, /*typical % of time used*/ 0.0) (pc_device)("personal computer", /*activation code*/ 42, /*typical % of time used*/ 100.0) )
Unfortunately, you can't put commas into one of the elements because then the BOOST_PP stuff thinks that you've no longer got a sequence data type, now you've got a tuple or some kind. This really looks like you'd like to have an arbitrary type to be used for each element of the enum. I'd really like that too, but haven't figured out a way to accomplish this. Also, we'd have to figure out what the best API would be to pull these values out.
participants (2)
-
Frank Laub
-
Job Mulder