Created
January 1, 2015 19:40
-
-
Save tilpner/cece8b05d3caec0d603e to your computer and use it in GitHub Desktop.
A generic way to set bits. Yeah, you don't have to like it...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Never really tested this... | |
#[inline(always)] | |
fn set_bit<T: One + BitOr<T, T> + BitAnd<T, T> + Shl<T, T> + Not<T>>(val: T, bit: T, on: bool) -> T { | |
if on { val | one::<T>() << bit } else { val & !(one::<T>() << bit) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment