Esempio n. 1
0
void EvtHandlerTestCase::BindFunctor()
{
    // generalized functor tests
    MyFunctor functor;

    handler.Bind( MyEventType, functor );
    g_called.Reset();
    handler.ProcessEvent(e);
    CPPUNIT_ASSERT( g_called.functor );
    handler.Unbind( MyEventType, functor );
    g_called.Reset();
    handler.ProcessEvent(e);
    CPPUNIT_ASSERT( !g_called.functor );

    handler.Bind( MyEventType, functor, 0 );
    handler.Unbind( MyEventType, functor, 0 );

    handler.Bind( MyEventType, functor, 0, 0 );
    handler.Unbind( MyEventType, functor, 0, 0 );

    // test that a temporary functor is working as well and also test that
    // unbinding a different (though equal) instance of the same functor does
    // not work
    MyFunctor func;
    handler.Bind( MyEventType, MyFunctor() );
    CPPUNIT_ASSERT( !handler.Unbind( MyEventType, func ));

    handler.Bind( MyEventType, MyFunctor(), 0 );
    CPPUNIT_ASSERT( !handler.Unbind( MyEventType, func, 0 ));

    handler.Bind( MyEventType, MyFunctor(), 0, 0 );
    CPPUNIT_ASSERT( !handler.Unbind( MyEventType, func, 0, 0 ));
}
Esempio n. 2
0
int main()
{
  auto x = std::make_tuple(5, 1.5, -1, ' ');
  auto y = apply_f(MyFunctor(), x);

  std::cout << "Before: " << x << " After: " << y << std::endl;
}
Esempio n. 3
0
void test_for_each()
{
    std::vector<int> v = {1, 2, 3, 4, 5, 6, 7, 100};
    for_each(v.begin(), v.end(), my_function);
    std::cout << std::endl;
    for_each(v.begin(), v.end(), MyFunctor(2));
    std::cout << std::endl;
}
Esempio n. 4
0
void testFunctor()
{
	PRINT_SCOPE;

	std::list<int> objects;
	const int size = 10;

	for (int i=0; i<size; ++i)
	{
		objects.push_back(i);
	}

	std::for_each(objects.begin(), objects.end(), MyFunctor());
	std::cout << std::endl;

	std::for_each(objects.begin(), objects.end(), [](int p){ std::cout << p << " "; });
	std::cout << std::endl;
}