Skip to content

Instantly share code, notes, and snippets.

@opensvn
Created May 11, 2021 03:34
Show Gist options
  • Save opensvn/207e1bf3528fdb8ca56163b2ace7138e to your computer and use it in GitHub Desktop.
Save opensvn/207e1bf3528fdb8ca56163b2ace7138e to your computer and use it in GitHub Desktop.
OnesCount
#include <iostream>
template <size_t Input>
constexpr size_t OnesCount = (Input % 2) + OnesCount<(Input / 2)>;
template <> constexpr size_t OnesCount<0> = 0;
int main() {
std::cout << OnesCount<45> << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment