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
- type_traits
- go
- c++
- traits
- RAII
- Clojure
- template
- stringprintf
- sprintf
- Scala
- Functional
- haskell
- Reflect
- kotlin
- web
- CustomTab
- Chrono
- WebView
- program
- Android
- async
- coroutines
- design pattern
- Observer
- SHA1
- SHA512
- AES
- sha256
- ranges
- ChromeTab
Archives
- Today
- Total
프로그래밍 검색 블로그
템플릿 메타 프로그래밍 팩토리얼 본문
1 2 3 4 5 6 7 8 9 | template<unsigned long long N> struct factorial{ static const unsigned long long value = N * factorial<N - 1>::value; }; template<> struct factorial<1LL>{ static const unsigned long long value = 1; }; | cs |
테스트
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <iostream> using namespace std; int main(){ cout << factorial<1>::value << endl; cout << factorial<2>::value << endl; cout << factorial<3>::value << endl; cout << factorial<4>::value << endl; cout << factorial<5>::value << endl; cout << factorial<6>::value << endl; cout << factorial<7>::value << endl; cout << factorial<8>::value << endl; cout << factorial<9>::value << endl; cout << factorial<10>::value << endl; } | cs |
'연습장' 카테고리의 다른 글
함수형 피타고라스 삼각형 구하기 (0) | 2017.10.14 |
---|---|
템플릿 메타 프로그래밍 소수 구하기 (0) | 2017.10.06 |
템플릿 메타 프로그래밍 피보나치 (0) | 2017.10.05 |
템플릿 메타 프로그래밍 최대공약수 최대공배수 (0) | 2017.10.05 |
템플릿 메타 프로그래밍 binary (0) | 2017.10.05 |
Comments