MCPcopy Create free account
hub / github.com/davisking/dlib / test_scope_exit

Function test_scope_exit

dlib/test/scope.cpp:18–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16// ---------------------------------------------------------------------------------------------------
17
18 void test_scope_exit()
19 {
20 int counter{0};
21
22 {
23 auto s1 = make_scope_exit([&]{++counter;});
24 static_assert(!std::is_copy_constructible<decltype(s1)>::value, "bad");
25 static_assert(!std::is_copy_assignable<decltype(s1)>::value, "bad");
26 static_assert(!std::is_move_assignable<decltype(s1)>::value, "bad");
27 static_assert(std::is_move_constructible<decltype(s1)>::value, "bad");
28 auto s2 = std::move(s1);
29 auto s3 = std::move(s2);
30 auto s4 = std::move(s3);
31 }
32
33 DLIB_TEST(counter == 1);
34
35 const auto fn_inner = [&]
36 {
37 auto s = make_scope_exit([&]{++counter;});
38 return s;
39 };
40
41 const auto fn_outer = [&]
42 {
43 auto s = fn_inner();
44 return s;
45 };
46
47 {
48 auto s = fn_outer();
49 }
50
51 DLIB_TEST(counter == 2);
52
53#ifdef __cpp_deduction_guides
54
55 {
56 scope_exit s{[&]{++counter;}};
57 }
58
59 DLIB_TEST(counter == 3);
60#endif
61
62 }
63
64// ---------------------------------------------------------------------------------------------------
65

Callers 1

perform_testMethod · 0.85

Calls 2

make_scope_exitFunction · 0.85
moveFunction · 0.85

Tested by

no test coverage detected