Sets yet again :)

Fredrik Olsson peylow at treyst.se
Thu Mar 9 08:39:31 PST 2006


Code says more than 1000 words:

enum StreamFeature { ISREADABLE = 1, ISWRITABLE = 2, ISSEEKABLE = 4 };
// ...
class Stream {
   StreamFeature features();
   // ...
}
// ...
if ((someStream.features() && StreamFeatures.ISREADABLE) != 0)
   // ...

Pros: works now
Cons: What is more than 32 features, ugly even if != 0 is dropped.

enum StreamFeature { ISREADABLE, ISWRITEABLE, ISSEEKABLE };
set StreamFeatures { StreamFeature };
//..
class Stream {
   StreamFeatures features();
   // ...
}
// ...
if (StreamFeature.ISREADABLE in stream.features())
   // ...

Pros: No limit, looks good, is self commenting, focus is on
       functionality not implementation
Cons: Well... requires set support or at the very least a standard
       set lib.

// Fredrik Olsson



More information about the Digitalmars-d mailing list