mirror of
https://github.com/TartanLlama/expected.git
synced 2026-01-25 16:42:20 +01:00
32 lines
916 B
C++
32 lines
916 B
C++
struct no_throw {
|
|
no_throw(std::string i) : i(i) {}
|
|
std::string i;
|
|
};
|
|
struct canthrow_move {
|
|
canthrow_move(std::string i) : i(i) {}
|
|
canthrow_move(canthrow_move const &) = default;
|
|
canthrow_move(canthrow_move &&other) noexcept(false) : i(other.i) {}
|
|
canthrow_move &operator=(canthrow_move &&) = default;
|
|
std::string i;
|
|
};
|
|
|
|
bool should_throw = false;
|
|
struct willthrow_move {
|
|
willthrow_move(std::string i) : i(i) {}
|
|
willthrow_move(willthrow_move const &) = default;
|
|
willthrow_move(willthrow_move &&other) : i(other.i) {
|
|
if (should_throw)
|
|
throw 0;
|
|
}
|
|
willthrow_move &operator=(willthrow_move &&) = default;
|
|
std::string i;
|
|
};
|
|
|
|
int main() {
|
|
std::string s1 = "abcdefghijklmnopqrstuvwxyz";
|
|
std::string s2 = "zyxwvutsrqponmlkjihgfedcbaxxx";
|
|
tl::expected<no_throw, willthrow_move> a{s1};
|
|
tl::expected<no_throw, willthrow_move> b{tl::unexpect, s2};
|
|
should_throw = 1;
|
|
swap(a, b);
|
|
} |