prepare for c++17

This commit is contained in:
Changkun Ou
2018-03-26 09:08:36 +02:00
parent 8a3eb8f271
commit 71025d8bc6
39 changed files with 28 additions and 11 deletions

34
code/2/2.2.cpp Normal file
View File

@@ -0,0 +1,34 @@
//
// 2.2.cpp
// c++1x tutorial
//
// created by changkun at shiyanlou.com
//
// constexpr
#include <iostream>
#define LEN 10
constexpr int len_foo() {
return 5;
}
constexpr int fibonacci(const int n) {
return n == 1 || n == 2 ? 1 : fibonacci(n-1)+fibonacci(n-2);
}
int main() {
char arr_1[10];
char arr_2[LEN];
const int len = 10;
char arr_3[len];
char arr_5[len_foo()+5];
std::cout << fibonacci(10) << std::endl;
// 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
return 0;
}