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

Function test_try_invoke

dlib/test/constexpr_if.cpp:133–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131 }
132
133 void test_try_invoke()
134 {
135 int value = 0;
136
137 auto foo = [&]{ value++; };
138 auto bar = [&](int i) { value += i; };
139 auto baz = [&](int i, int j) { value += (i+j); };
140
141 DLIB_TEST(try_invoke(foo));
142 DLIB_TEST(value == 1);
143 DLIB_TEST(!try_invoke(foo, 1));
144 DLIB_TEST(value == 1);
145 DLIB_TEST(!try_invoke(foo, 1, 2));
146 DLIB_TEST(value == 1);
147
148 DLIB_TEST(!try_invoke(bar));
149 DLIB_TEST(value == 1);
150 DLIB_TEST(try_invoke(bar, 1));
151 DLIB_TEST(value == 2);
152 DLIB_TEST(!try_invoke(bar, 1, 2));
153 DLIB_TEST(value == 2);
154
155 DLIB_TEST(!try_invoke(baz));
156 DLIB_TEST(value == 2);
157 DLIB_TEST(!try_invoke(baz, 1));
158 DLIB_TEST(value == 2);
159 DLIB_TEST(try_invoke(baz, 1, 2));
160 DLIB_TEST(value == 5);
161 }
162
163 template<typename T>
164 using set_i_pred = decltype(std::declval<T>().set_i(int{}));

Callers 1

perform_testMethod · 0.85

Calls 1

try_invokeFunction · 0.85

Tested by

no test coverage detected