Skip to content

Instantly share code, notes, and snippets.

@Furkanzmc
Created June 11, 2021 04:54
Show Gist options
  • Save Furkanzmc/7eeb508512fca6f4368054e636e2acae to your computer and use it in GitHub Desktop.
Save Furkanzmc/7eeb508512fca6f4368054e636e2acae to your computer and use it in GitHub Desktop.
struct Point {
int x;
int y;
Point() : x{0}, y{0} { std::clog << "Point()\n"; }
Point(int _x, int _y) : x{_x}, y{_y} {
std::clog << "Point(int _x, int _y)\n";
}
Point(const Point &other) : x{other.x}, y{other.y} {
std::clog << "Point(const Point&)\n";
}
Point(Point &&other) : x{other.x}, y{other.y} {
other.x = 0;
other.y = 0;
std::clog << "Point(Point&&)\n";
}
Point &operator=(const Point &other) {
x = other.x;
y = other.y;
std::clog << "&operator=(const Point &)\n";
return *this;
}
Point &operator=(Point &&other) {
x = other.x;
y = other.y;
other.x = 0;
other.y = 0;
std::clog << "&operator=(Point &&)\n";
return *this;
}
};
TEST_CASE("Result with Compund Types") {
Point p = to_point("2").expect([](const zmc::Error &err) {});
CHECK(p.x == 2);
CHECK(p.y == 2);
}
/* Here's the output:
Point(int _x, int _y)
Point(Point&&)
Point(Point&&)
Point(Point&&)
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment