Skip to content

Commit

Permalink
[IM]: C++14
Browse files Browse the repository at this point in the history
  • Loading branch information
liujj committed Aug 8, 2022
1 parent 174cd08 commit 9fc1ea8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 04.c++14/01.数字分隔符.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <chrono>
using namespace std;

int main()
{
auto a = 1'234'567; // 1234567 整数
auto b = 1'234'56s; // 1234567秒 // std::chrono::milliseconds

cout << a << endl;
cout << b.count() << endl;
return 0;
}
14 changes: 14 additions & 0 deletions 04.c++14/02.函数返回值类型推导.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
using namespace std;

template<typename T>
auto func(T i)
{
return i;
}

int main()
{
cout << func("C++14") << endl;
return 0;
}
10 changes: 10 additions & 0 deletions 04.c++14/03.auto.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
using namespace std;

int main() {

auto f = [](auto a) { return a; };

cout << f("c++14") << endl;
return 0;
}
29 changes: 29 additions & 0 deletions 04.c++14/04.变量模版.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;

template<class T>
constexpr T pi = T(3.1415926535897932385L);

template<typename T, typename U>
struct A {
T t;
U u;
};

template<typename T>
using B = A<T, int>;

int main() {

cout << pi<int> << endl; // 3
cout << pi<double> << endl; // 3.14159


B<double> b;
b.t = 10;
b.u = 20;
cout << b.t << endl;
cout << b.u << endl;

return 0;
}
8 changes: 8 additions & 0 deletions 04.c++14/05.constexpr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>
using namespace std;

int main() {

cout << "hello, world!" << endl;
return 0;
}

0 comments on commit 9fc1ea8

Please sign in to comment.