[Python-ideas] IntFlags

Eugene Toder eltoder at gmail.com
Thu Mar 5 23:07:04 CET 2015


On Thu, Mar 5, 2015 at 3:30 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:

> Concerning ~, if you think of it as a set, then ~x should
> be the result of exlusive-oring x with an int containing
> all the valid bits, i.e. the value obtained by oring all
> the defined values together.
>
Yes, that will work. Then we might want predefined constants for all set
bits and zero. (Zero can be just calling MyBitSet() with no arguments).
Then ~X is type(X).ALL_ONES - X.
The main question is whether this operation makes much sense. I think in
practice ~ is only used with flags to clear bits (X & ~Y), which can be
done in one explicit operation. It may still be worth supporting ~ to allow
painless transition from plain ints.

Eugene
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150305/552477d7/attachment-0001.html>


More information about the Python-ideas mailing list