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

Function test_function

dlib/test/te.cpp:316–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314
315 template<typename Function>
316 void test_function()
317 {
318 Function f1;
319 DLIB_TEST(!f1);
320
321 int a = 42;
322 Function f2{[a](int b) {return a + b;}};
323 DLIB_TEST(f2);
324 DLIB_TEST(f2(1) == 43);
325
326 Function f3{f2};
327 DLIB_TEST(f2);
328 DLIB_TEST(f3);
329 DLIB_TEST(f2(2) == 44);
330 DLIB_TEST(f3(2) == 44);
331
332 f1 = f2;
333 DLIB_TEST(f1);
334 DLIB_TEST(f2);
335 DLIB_TEST(f3);
336 DLIB_TEST(f1(2) == 44);
337 DLIB_TEST(f2(2) == 44);
338 DLIB_TEST(f3(2) == 44);
339
340 Function f4{std::move(f2)};
341 DLIB_TEST(f1);
342 DLIB_TEST(!f2);
343 DLIB_TEST(f3);
344 DLIB_TEST(f4);
345 DLIB_TEST(f1(2) == 44);
346 DLIB_TEST(f3(2) == 44);
347 DLIB_TEST(f4(2) == 44);
348
349 f2 = std::move(f1);
350 DLIB_TEST(!f1);
351 DLIB_TEST(f2);
352 DLIB_TEST(f3);
353 DLIB_TEST(f4);
354 DLIB_TEST(f2(2) == 44);
355 DLIB_TEST(f3(2) == 44);
356 DLIB_TEST(f4(2) == 44);
357 }
358
359 void test_function_view()
360 {

Callers

nothing calls this directly

Calls 1

moveFunction · 0.85

Tested by

no test coverage detected