-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom1.cpp
55 lines (48 loc) · 1.22 KB
/
custom1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "argparse.h"
#include <string>
#include <sstream>
#include <cmath>
namespace geometry
{
struct Point
{
Point() = default;
Point(int x, int y) : x(x), y(y)
{
}
int x = 0;
int y = 0;
};
}
namespace argparse
{
template<>
inline auto from_string(std::string const & s, geometry::Point & p) -> bool
{
std::istringstream iss(s);
char comma;
iss >> p.x >> comma >> p.y;
return !iss.fail();
}
template<>
inline auto to_string(geometry::Point const & p) -> std::string
{
return std::to_string(p.x) + "," + std::to_string(p.y);
}
template<>
inline auto are_equal(geometry::Point const & l, geometry::Point const & r) -> bool
{
return l.x == r.x && l.y == r.y;
}
}
auto main(int argc, char * argv[]) -> int
{
auto parser = argparse::ArgumentParser();
parser.add_argument("start").type<geometry::Point>();
parser.add_argument("end").type<geometry::Point>();
auto parsed = parser.parse_args(argc, argv);
auto start = parsed.get_value<geometry::Point>("start");
auto end = parsed.get_value<geometry::Point>("end");
auto distance = std::hypot(end.x - start.x, end.y - start.y);
std::cout << "The distance is " << distance << '\n';
}