-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bitwise operations for integer_ops #135
Comments
Motivating example. On windows |
If you define your type like this struct my_access_mask : type_safe::strong_typedef<my_access_mask, DWORD>,
type_safe::strong_typedef_op::bitmask<my_access_mask>
{
using strong_typedef::strong_typedef;
};
my_access_mask add_read(my_access_mask mask) {
return mask & my_access_mask{ GENERIC_READ };
} you get what you want, I think. Godbolt link https://godbolt.org/z/6Knj6sjbq See Jonathan's blog post/tutorial as well, for some background on how to use this very useful library |
I did not notice the bitmask op existed thank you. Perhaps this could be added to the integer ops by default, I had expected them to be present there. |
hmm doing |
I'm trying to make an explicit distinction between "integer operations" and "bit operations". In my opinion, integers and bit strings are different types and should be treated differently.
The library explicitly tries to prevent implicit conversions. If you want, you can always write one: struct my_access_mask : type_safe::strong_typedef<my_access_mask, DWORD>,
type_safe::strong_typedef_op::bitmask<my_access_mask>
{
using strong_typedef::strong_typedef;
operator bool() const
{ return static_cast<DWORD>(*this) != 0; }
};
my_access_mask add_read(my_access_mask mask) {
return mask & my_access_mask{ GENERIC_READ };
} You might also be interested in using |
Cool library!
The
type_safe::strong_typedef_op
could use the bitwise operations like &, |, ~, etc. For the integer op type these should probably be default.The text was updated successfully, but these errors were encountered: