Created
December 23, 2012 17:05
-
-
Save ElemarJR/4364455 to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
template <unsigned long N> | |
struct binary { | |
static unsigned const value = | |
binary<N/10>::value * 2 | |
+ N % 10; | |
}; | |
template <> | |
struct binary<0> { | |
static unsigned const value = 0; | |
}; | |
int main() | |
{ | |
unsigned const two = binary<10>::value; | |
unsigned const five = binary<101>::value; | |
std::cout | |
<< two << std::endl | |
<< five << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment