Created
July 31, 2017 09:14
-
-
Save meritozh/c9c6ce2044d157a89156a3dada943465 to your computer and use it in GitHub Desktop.
C++ template div integer to even and odd.
This file contains hidden or 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
#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