Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- kotlin
- template
- sprintf
- Functional
- type_traits
- ranges
- RAII
- Android
- WebView
- haskell
- coroutines
- go
- program
- stringprintf
- c++
- AES
- sha256
- CustomTab
- Scala
- design pattern
- SHA1
- traits
- SHA512
- Chrono
- async
- Reflect
- Clojure
- Observer
- web
- ChromeTab
Archives
- Today
- Total
프로그래밍 검색 블로그
템플릿 메타 프로그래밍 binary 본문
1 2 3 4 5 6 7 8 9 10 11 12 | template<unsigned long long N> struct binary{ static const unsigned long long value = binary<N % 10LL>::value + 2 * binary<N / 10LL>::value; }; template<> struct binary<1LL>{ static const unsigned long long value = 1; }; template<> struct binary<0LL>{ static const unsigned long long value = 0; }; | cs |
테스트
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> using namespace std; int main(){ cout << binary<0>::value << endl; cout << binary<1>::value << endl; cout << binary<10>::value << endl; cout << binary<11>::value << endl; cout << binary<100>::value << endl; cout << binary<101>::value << endl; cout << binary<110>::value << endl; cout << binary<111>::value << endl; cout << binary<1000>::value << endl; cout << binary<1001>::value << endl; cout << binary<1010>::value << endl; //error //cout << binary<2>::value << endl; } | cs |
'연습장' 카테고리의 다른 글
함수형 피타고라스 삼각형 구하기 (0) | 2017.10.14 |
---|---|
템플릿 메타 프로그래밍 소수 구하기 (0) | 2017.10.06 |
템플릿 메타 프로그래밍 피보나치 (0) | 2017.10.05 |
템플릿 메타 프로그래밍 최대공약수 최대공배수 (0) | 2017.10.05 |
템플릿 메타 프로그래밍 팩토리얼 (0) | 2017.10.05 |
Comments