|
Boost : |
From: Moore, Paul (Paul.Moore_at_[hidden])
Date: 1999-12-10 05:32:38
From: Kevlin Henney [mailto:Kevlin.Henney_at_[hidden]]
> This sounds like a call for enum traits, which is an idea I
> was playing with a couple of years ago. The intent was to
> make more compile time information about enums available,
> and support automatic sets of operations, including iteration.
>
> It might be worth dusting that stuff off, revise and boost it. Any
> interest?
Yes, definitely. But can useful things be done without compiler support or
extensive specialisation on a per-enumeration basis?
The thing I find I need most often is a to_string() or output method, which
gives a symbolic result. Code like
enum colour { RED, GREEN, BLUE };
ostream& operator<< (ostream& os, colour c)
{
switch (c) {
case RED: os << "RED"; break;
case GREEN: os << "GREEN"; break;
case BLUE: os << "BLUE"; break;
}
return os;
}
rapidly gets tedious and error prone.
But I really don't see how it can be automated without some form of compiler
support. After all, there's the case of
enum bits { bit0=1, bit1=2, bit2=4, bit3=8 };
bits b = bit1|bit3;
cerr << "Debug: b = " << b << endl;
Paul.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk