Sets yet again :)

Hasan Aljudy hasan.aljudy at gmail.com
Thu Mar 9 19:30:00 PST 2006


Fredrik Olsson wrote:
> 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

Just write a set class. It's not /that/ hard.



More information about the Digitalmars-d mailing list