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

Function test_member_pointer

dlib/test/te.cpp:413–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

411
412 template<template<class...> class Function, class Storage>
413 void test_member_pointer()
414 {
415 {
416 member_function obj;
417
418 Function<Storage, void(member_function&, int&)> f{&member_function::increment};
419 DLIB_TEST(f);
420 int a = 0;
421 f(obj, a);
422 DLIB_TEST(a == 1);
423
424 f = nullptr;
425 DLIB_TEST(!f);
426 f = &member_function::increment;
427 DLIB_TEST(f);
428 f(obj, a);
429 DLIB_TEST(a == 2);
430 }
431
432 /*! Use std::mem_fn !*/
433 {
434 member_function obj;
435
436 Function<Storage, void(member_function&, int&)> f{std::mem_fn(&member_function::increment)};
437 DLIB_TEST(f);
438 int a = 0;
439 f(obj, a);
440 DLIB_TEST(a == 1);
441
442 f = nullptr;
443 DLIB_TEST(!f);
444 f = std::mem_fn(&member_function::increment);
445 DLIB_TEST(f);
446 f(obj, a);
447 DLIB_TEST(a == 2);
448 }
449
450 /*! Use std::bind !*/
451 {
452 using namespace std::placeholders;
453
454 member_function obj;
455
456 Function<Storage, void(int&)> f{std::bind(&member_function::increment, obj, _1)};
457 DLIB_TEST(f);
458 int a = 0;
459 f(a);
460 DLIB_TEST(a == 1);
461
462 f = nullptr;
463 DLIB_TEST(!f);
464 f = std::bind(&member_function::increment, obj, _1);
465 DLIB_TEST(f);
466 f(a);
467 DLIB_TEST(a == 2);
468 }
469 }
470

Callers

nothing calls this directly

Calls 2

bindClass · 0.85
fFunction · 0.70

Tested by

no test coverage detected