[MEC++]这样一个宏该怎么写?
《More Exceptional C++》的Item 34中,Sutter提到了宏的以下用法,
可是他说的这个 ERR_ENTRY 宏该怎么写呢?多谢。
c) Variant Data Representations
A common example is that a module may define a list of error codes, which
outside users should see as a simple enum with comments, but which inside
the module should be stored in a map for easy lookup. That is:
// For outsiders
//
enum Error
{
ERR_OK = 0, // No error
ERR_INVALID_PARAM = 1, // <description>
...
};
// For the module's internal use
//
map<Error,const char*> lookup;
lookup.insert( make_pair( ERR_OK,
(const char*)"No error" ) );
lookup.insert( make_pair( ERR_INVALID_PARAM,
(const char*)"<description>" ) );
...
We'd like to have both representations, without defining the actual
information (code/message pairs) twice. With macro magic, we can simply
write a list of errors as follows, creating the appropriate structure
at compile time:
ERR_ENTRY( ERR_OK, 0, "No error" ),
ERR_ENTRY( ERR_INVALID_PARAM, 1, "<description>" ),
...
The implementations of ERR_ENTRY and related macros is left to the reader.