How do I defeat the gratuitous qualification of alias members?
Ali Çehreli
acehreli at yahoo.com
Thu Apr 4 22:23:30 PDT 2013
On 04/04/2013 08:50 PM, Chad Joan wrote:
> There has to be a better way!
You seem to be looking for the (to me) only sensible use of 'with': :)
enum SANE_Status
{
SANE_STATUS_GOOD = 0,
SANE_STATUS_UNSUPPORTED,
}
void foo(SANE_Status s)
{
final switch (s) with (SANE_Status) {
case SANE_STATUS_GOOD: break;
case SANE_STATUS_UNSUPPORTED: break;
}
}
void main()
{
foo(SANE_Status.SANE_STATUS_GOOD);
}
If acceptable for you, I also recommend dropping the SANE_STATUS_ prefix
from the values:
enum SANE_Status
{
GOOD = 0,
UNSUPPORTED,
}
void foo(SANE_Status s)
{
final switch (s) with (SANE_Status) {
case GOOD: break;
case UNSUPPORTED: break;
}
}
void main()
{
foo(SANE_Status.GOOD);
}
Further, camel-casing the type and the values:
enum SaneStatus
{
good = 0,
unsupported,
}
void foo(SaneStatus s)
{
final switch (s) with (SaneStatus) {
case good: break;
case unsupported: break;
}
}
void main()
{
foo(SaneStatus.good);
}
Ali
More information about the Digitalmars-d-learn
mailing list