| 1234567891011121314151617181920212223242526272829303132 |
- 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);
- }
|