Skip to content

Instantly share code, notes, and snippets.

@meritozh
Created July 31, 2017 09:14
Show Gist options
  • Save meritozh/c9c6ce2044d157a89156a3dada943465 to your computer and use it in GitHub Desktop.
Save meritozh/c9c6ce2044d157a89156a3dada943465 to your computer and use it in GitHub Desktop.
C++ template div integer to even and odd.
#include <iostream>
template <int I>
void div( char(*)[I % 2 == 0] = 0 ) {
std::cout << "even!!!" << std::endl;
}
template <int I>
void div( char(*)[I % 2 == 1] = 0 ) {
std::cout << "odd!!!" << std::endl;
}
int main() {
div<5>();
div<6>();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment