Skip to content

Commit fc192e2

Browse files
committed
use tie and swap typedef for using
1 parent 10ebadf commit fc192e2

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

contents/verlet_integration/code/c++/verlet.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <iostream>
33
#include <utility>
44

5-
typedef std::pair<double, double> vpair;
5+
using vpair = std::pair<double, double>;
66

77
double verlet(double pos, double acc, double dt) {
88

@@ -19,7 +19,7 @@ double verlet(double pos, double acc, double dt) {
1919
return time;
2020
}
2121

22-
std::pair<double, double> stormer_verlet(double pos, double acc, double dt) {
22+
vpair stormer_verlet(double pos, double acc, double dt) {
2323

2424
double prev_pos = pos;
2525
double time = 0;
@@ -38,7 +38,7 @@ std::pair<double, double> stormer_verlet(double pos, double acc, double dt) {
3838
return std::make_pair(time, vel);
3939
}
4040

41-
std::pair<double, double> velocity_verlet(double pos, double acc, double dt) {
41+
vpair velocity_verlet(double pos, double acc, double dt) {
4242

4343
double time = 0;
4444
double vel = 0;
@@ -53,7 +53,6 @@ std::pair<double, double> velocity_verlet(double pos, double acc, double dt) {
5353

5454
int main() {
5555
double time, vel;
56-
vpair time_vel_pair;
5756

5857
std::cout << std::fixed << std::setprecision(8);
5958

@@ -68,21 +67,18 @@ int main() {
6867
std::cout << "Time for Verlet integration is: " \
6968
<< time << std::endl;
7069

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);
7471
std::cout << "Time for Stormer Verlet integration is: " \
7572
<< time << std::endl;
7673
std::cout << "Velocity for Stormer Verlet integration is: " \
7774
<< vel << std::endl;
7875

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);
8277
std::cout << "Time for velocity Verlet integration is: " \
8378
<< time << std::endl;
8479
std::cout << "Velocity for velocity Verlet integration is: " \
8580
<< vel << std::endl;
8681

8782
return 0;
83+
8884
}

0 commit comments

Comments
 (0)