Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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