Boost logo

Boost :

Subject: Re: [boost] enum / string translation
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-07-27 11:57:50

Celtic Minstrel wrote:
> My own solution for scoping enums has been to enclose it in a
> namespace rather than a class, and import the name of the actual enum.
> The only disadvantage is that the namespace must have a different name
> than the enum; perhaps your solution is better.

Putting them in a class allows defining operators on the class type that aren't possible on an enumerated type (|=, ^=, etc.). The member functions can be expressed as namespace scope functions, and the static member that holds the maps, can be expressed as a namespace scope variable. However, a class offers privacy not available with a namespace. Thus, a class permits private member functions and data members to better control manipulations.

BTW, my reverse lookup (string-to-enumerator) map is populated on first access. The forward direction is done via the registration calls, but the reverse lookup can be built from the forward mappings. That saves memory for the many cases in which the reverse lookup isn't needed. It could, though I never did it, be triggered specifically at initialization time to avoid the first access overhead. There could be a specific call or some flag to indicate whether to do the reverse lookup initialization on first access or early.

> Of course, C++0x enum classes beat either option.


Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at