| 65 | |
| 66 | |
| 67 | void test_scope_exit_erased() |
| 68 | { |
| 69 | int counter{0}; |
| 70 | |
| 71 | { |
| 72 | scope_exit_erased s1([&]{++counter;}); |
| 73 | static_assert(!std::is_copy_constructible<decltype(s1)>::value, "bad"); |
| 74 | static_assert(!std::is_copy_assignable<decltype(s1)>::value, "bad"); |
| 75 | static_assert(!std::is_move_assignable<decltype(s1)>::value, "bad"); |
| 76 | static_assert(std::is_move_constructible<decltype(s1)>::value, "bad"); |
| 77 | auto s2 = std::move(s1); |
| 78 | auto s3 = std::move(s2); |
| 79 | auto s4 = std::move(s3); |
| 80 | } |
| 81 | |
| 82 | DLIB_TEST(counter == 1); |
| 83 | |
| 84 | const auto fn_inner = [&] |
| 85 | { |
| 86 | scope_exit_erased s([&]{++counter;}); |
| 87 | return s; |
| 88 | }; |
| 89 | |
| 90 | const auto fn_outer = [&] |
| 91 | { |
| 92 | auto s = fn_inner(); |
| 93 | return s; |
| 94 | }; |
| 95 | |
| 96 | { |
| 97 | auto s = fn_outer(); |
| 98 | } |
| 99 | |
| 100 | DLIB_TEST(counter == 2); |
| 101 | } |
| 102 | |
| 103 | struct results_with_delayed_C_library_resource_management |
| 104 | { |