Created
June 11, 2021 04:54
-
-
Save Furkanzmc/7eeb508512fca6f4368054e636e2acae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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