2
2
#include < iostream>
3
3
#include < utility>
4
4
5
- typedef std::pair<double , double > vpair ;
5
+ using vpair = std::pair<double , double >;
6
6
7
7
double verlet (double pos, double acc, double dt) {
8
8
@@ -19,7 +19,7 @@ double verlet(double pos, double acc, double dt) {
19
19
return time;
20
20
}
21
21
22
- std::pair< double , double > stormer_verlet (double pos, double acc, double dt) {
22
+ vpair stormer_verlet (double pos, double acc, double dt) {
23
23
24
24
double prev_pos = pos;
25
25
double time = 0 ;
@@ -38,7 +38,7 @@ std::pair<double, double> stormer_verlet(double pos, double acc, double dt) {
38
38
return std::make_pair (time, vel);
39
39
}
40
40
41
- std::pair< double , double > velocity_verlet (double pos, double acc, double dt) {
41
+ vpair velocity_verlet (double pos, double acc, double dt) {
42
42
43
43
double time = 0 ;
44
44
double vel = 0 ;
@@ -53,7 +53,6 @@ std::pair<double, double> velocity_verlet(double pos, double acc, double dt) {
53
53
54
54
int main () {
55
55
double time, vel;
56
- vpair time_vel_pair;
57
56
58
57
std::cout << std::fixed << std::setprecision (8 );
59
58
@@ -68,21 +67,18 @@ int main() {
68
67
std::cout << " Time for Verlet integration is: " \
69
68
<< time << std::endl;
70
69
71
- time_vel_pair = stormer_verlet (5.0 , -10 , 0.01 );
72
- time = time_vel_pair.first ;
73
- vel = time_vel_pair.second ;
70
+ std::tie (time, vel) = stormer_verlet (5.0 , -10 , 0.01 );
74
71
std::cout << " Time for Stormer Verlet integration is: " \
75
72
<< time << std::endl;
76
73
std::cout << " Velocity for Stormer Verlet integration is: " \
77
74
<< vel << std::endl;
78
75
79
- time_vel_pair = velocity_verlet (5.0 , -10 , 0.01 );
80
- time = time_vel_pair.first ;
81
- vel = time_vel_pair.second ;
76
+ std::tie (time, vel) = velocity_verlet (5.0 , -10 , 0.01 );
82
77
std::cout << " Time for velocity Verlet integration is: " \
83
78
<< time << std::endl;
84
79
std::cout << " Velocity for velocity Verlet integration is: " \
85
80
<< vel << std::endl;
86
81
87
82
return 0 ;
83
+
88
84
}
0 commit comments