Created
November 3, 2020 19:43
-
-
Save hrkrshnn/07834c45cc8c270205fab2fc688c0f6f to your computer and use it in GitHub Desktop.
A test to see if objects can be moved out of optional
This file contains hidden or 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
#include <iostream> | |
#include <optional> | |
struct A | |
{ | |
A() { } | |
A(A const& a) { std::cout << "move construction failed!\n"; } | |
A(A&& o) { std::cout << "moved construction worked!\n"; } | |
A& operator=(A const& other) { | |
std::cout << "move assignment failed!\n"; | |
return *this; | |
} | |
A& operator=(A&& other) { | |
std::cout << "move assignment worked!\n"; | |
return *this; | |
} | |
}; | |
int main() | |
{ | |
// move construction worked | |
std::optional<A> test = A(); | |
A b; | |
// move assignment worked | |
b = std::move(*test); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment