Update contrib.
4 #include "cppunit/cppunit_proxy.h"
6 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
13 class BindTest : public CPPUNIT_NS::TestCase
15 CPPUNIT_TEST_SUITE(BindTest);
16 CPPUNIT_TEST(bind1st1);
17 CPPUNIT_TEST(bind2nd1);
18 CPPUNIT_TEST(bind2nd2);
19 #if !defined (STLPORT) || \
20 defined (_STLP_NO_EXTENSIONS) || !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
23 CPPUNIT_TEST(bind2nd3);
24 CPPUNIT_TEST(bind_memfn);
25 CPPUNIT_TEST_SUITE_END();
35 CPPUNIT_TEST_SUITE_REGISTRATION(BindTest);
38 // tests implementation
40 void BindTest::bind1st1()
42 int array [3] = { 1, 2, 3 };
43 int* p = remove_if((int*)array, (int*)array + 3, bind1st(less<int>(), 2));
45 CPPUNIT_ASSERT(p==&array[2]);
46 CPPUNIT_ASSERT(array[0]==1);
47 CPPUNIT_ASSERT(array[1]==2);
49 void BindTest::bind2nd1()
51 int array [3] = { 1, 2, 3 };
52 replace_if(array, array + 3, binder2nd<greater<int> >(greater<int>(), 2), 4);
54 CPPUNIT_ASSERT(array[0]==1);
55 CPPUNIT_ASSERT(array[1]==2);
56 CPPUNIT_ASSERT(array[2]==4);
58 void BindTest::bind2nd2()
60 int array [3] = { 1, 2, 3 };
61 replace_if(array, array + 3, bind2nd(greater<int>(), 2), 4);
62 CPPUNIT_ASSERT(array[0]==1);
63 CPPUNIT_ASSERT(array[1]==2);
64 CPPUNIT_ASSERT(array[2]==4);
67 int test_func1 (const int ¶m1, const int ¶m2) {
68 return param1 + param2;
71 int test_func2 (int ¶m1, int param2) {
73 return param1 + param2;
76 void BindTest::bind2nd3()
78 #if defined (STLPORT) && \
79 !defined (_STLP_NO_EXTENSIONS) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
80 int array[3] = { 1, 2, 3 };
81 transform(array, array + 3, array, bind2nd(ptr_fun(test_func1), 1));
82 transform(array, array + 3, array, bind1st(ptr_fun(test_func1), -1));
83 CPPUNIT_ASSERT(array[0] == 1);
84 CPPUNIT_ASSERT(array[1] == 2);
85 CPPUNIT_ASSERT(array[2] == 3);
87 transform(array, array + 3, array, bind2nd(ptr_fun(test_func2), 10));
88 CPPUNIT_ASSERT(array[0] == 21);
89 CPPUNIT_ASSERT(array[1] == 22);
90 CPPUNIT_ASSERT(array[2] == 23);
101 void f( int n ) const
111 void BindTest::bind_memfn()
113 #if defined (STLPORT) && \
114 !defined (_STLP_NO_EXTENSIONS) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
117 for_each( array, array + 3, bind2nd( mem_fun_ref(&A::f), 12 ) );
119 CPPUNIT_CHECK( array[0].v() == 12 );