Skip to content

Instantly share code, notes, and snippets.

@hrkrshnn
Created November 3, 2020 19:43
Show Gist options
  • Save hrkrshnn/07834c45cc8c270205fab2fc688c0f6f to your computer and use it in GitHub Desktop.
Save hrkrshnn/07834c45cc8c270205fab2fc688c0f6f to your computer and use it in GitHub Desktop.
A test to see if objects can be moved out of optional
#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