Skip to content

Instantly share code, notes, and snippets.

@merryhime
Created March 30, 2017 16:39
Show Gist options
  • Save merryhime/6a8b2f411add8fa750f9ff00d6ab88ac to your computer and use it in GitHub Desktop.
Save merryhime/6a8b2f411add8fa750f9ff00d6ab88ac to your computer and use it in GitHub Desktop.
template <typename T>
constexpr T pext(T x, T mask) {
T ret = 0;
for (T bb = 1; mask != 0; bb += bb) {
if (x & mask & -mask) {
ret |= bb;
}
mask &= (mask - 1);
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment