Skip to content

Commit 80e215a

Browse files
committed
test04.cpp
1 parent 9ba46ec commit 80e215a

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

section1/test04.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@
1111
#include <stdexcept>
1212
#include <type_traits>
1313

14+
template<int N>
15+
struct fib
16+
{
17+
static const int value =
18+
fib<N - 1>::value + fib<N - 2>::value;
19+
};
20+
21+
template<>
22+
struct fib<0>
23+
{
24+
static const int value = 1;
25+
};
26+
27+
template<>
28+
struct fib<1>
29+
{
30+
static const int value = 1;
31+
};
32+
1433
//[[deprecated("deadline:2020-12-31")]] // c+14 or later
1534
[[gnu::deprecated]] // c+11 or later
1635
int old_func()
@@ -67,6 +86,7 @@ void case3()
6786

6887
void case4()
6988
{
89+
static_assert(sizeof(int) == 4, "int must be 32bit");
7090
static_assert(sizeof(long) >= 8, "must run on x64");
7191
}
7292

@@ -86,6 +106,12 @@ void check_type(T v)
86106

87107
int main()
88108
{
109+
using namespace std;
110+
111+
cout << fib<2>::value << endl;
112+
cout << fib<3>::value << endl;
113+
cout << fib<5>::value << endl;
114+
89115
old_func();
90116
get_num();
91117

0 commit comments

Comments
 (0)