프로그래밍 검색 블로그

템플릿 메타 프로그래밍 팩토리얼 본문

연습장

템플릿 메타 프로그래밍 팩토리얼

코딩조무사 2017. 10. 5. 22:16
1
2
3
4
5
6
7
8
9
template<unsigned long long N>
struct factorial{
    static const unsigned long long value = N * factorial<- 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



Comments