ReactOS 0.4.15-dev-8344-g0574987
bind_test.cpp
Go to the documentation of this file.
1#include <algorithm>
2#include <functional>
3
5
6#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
7using namespace std;
8#endif
9
10//
11// TestCase class
12//
13class BindTest : public CPPUNIT_NS::TestCase
14{
19#if !defined (STLPORT) || \
20 defined (_STLP_NO_EXTENSIONS) || !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
22#endif
26
27protected:
28 void bind1st1();
29 void bind2nd1();
30 void bind2nd2();
31 void bind2nd3();
32 void bind_memfn();
33};
34
36
37class pre_increment : public binary_function<int, int, int> {
38public:
39 int operator()(int incr, int& val) const
40 { return val += incr; }
41};
42
43class post_increment : public binary_function<int, int, int> {
44public:
45 int operator()(int& val, int incr) const
46 { return val += incr; }
47};
48
49
50//
51// tests implementation
52//
54{
55 int array [3] = { 1, 2, 3 };
56 int* p = remove_if((int*)array, (int*)array + 3, bind1st(less<int>(), 2));
57
58 CPPUNIT_ASSERT(p == &array[2]);
59 CPPUNIT_ASSERT(array[0] == 1);
60 CPPUNIT_ASSERT(array[1] == 2);
61
62 for_each((int*)array, (int*)array + 3, bind1st(pre_increment(), 1));
63 CPPUNIT_ASSERT(array[0] == 2);
64 CPPUNIT_ASSERT(array[1] == 3);
65 CPPUNIT_ASSERT(array[2] == 4);
66
67 for_each((int*)array, (int*)array + 3, bind2nd(post_increment(), 1));
68 CPPUNIT_ASSERT(array[0] == 3);
69 CPPUNIT_ASSERT(array[1] == 4);
70 CPPUNIT_ASSERT(array[2] == 5);
71}
72
74{
75 int array [3] = { 1, 2, 3 };
77
78 CPPUNIT_ASSERT(array[0]==1);
79 CPPUNIT_ASSERT(array[1]==2);
80 CPPUNIT_ASSERT(array[2]==4);
81}
83{
84 int array [3] = { 1, 2, 3 };
86 CPPUNIT_ASSERT(array[0]==1);
87 CPPUNIT_ASSERT(array[1]==2);
88 CPPUNIT_ASSERT(array[2]==4);
89}
90
91int test_func1 (const int &param1, const int &param2) {
92 return param1 + param2;
93}
94
95int test_func2 (int &param1, int param2) {
96 param1 += param2;
97 return param1 + param2;
98}
99
101{
102#if defined (STLPORT) && \
103 !defined (_STLP_NO_EXTENSIONS) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
104 int array[3] = { 1, 2, 3 };
107 CPPUNIT_ASSERT(array[0] == 1);
108 CPPUNIT_ASSERT(array[1] == 2);
109 CPPUNIT_ASSERT(array[2] == 3);
110
112 CPPUNIT_ASSERT(array[0] == 21);
113 CPPUNIT_ASSERT(array[1] == 22);
114 CPPUNIT_ASSERT(array[2] == 23);
115#endif
116}
117
118class A
119{
120 public:
121 A() : m_n( 0 )
122 {}
123
124 void f( int n ) const {
125#if defined (STLPORT)
126 _STLP_MUTABLE(A, m_n) = n;
127#else
128 m_n = n;
129#endif
130 }
131
132 int v() const
133 { return m_n; }
134
135 private:
136 mutable int m_n;
137};
138
140{
141#if defined (STLPORT) && \
142 !defined (_STLP_NO_EXTENSIONS) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
143 A array[3];
144
145 for_each( array, array + 3, bind2nd( mem_fun_ref(&A::f), 12 ) );
146
147 CPPUNIT_CHECK( array[0].v() == 12 );
148#endif
149}
_STLP_INLINE_LOOP void replace_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred, const _Tp &__new_value)
Definition: _algo.h:190
_STLP_BEGIN_NAMESPACE _STLP_INLINE_LOOP _Function for_each(_InputIter __first, _InputIter __last, _Function __f)
Definition: _algo.h:59
_STLP_INLINE_LOOP _ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred)
Definition: _algo.h:278
binder1st< _Operation > bind1st(const _Operation &__fn, const _Tp &__x)
Definition: _function.h:217
binder2nd< _Operation > bind2nd(const _Operation &__fn, const _Tp &__x)
Definition: _function.h:252
pointer_to_unary_function< _Arg, _Result > ptr_fun(_Result(*__f)(_Arg))
mem_fun_ref_t< _Result, _Tp > mem_fun_ref(_Result(_Tp::*__f)())
int test_func2(int &param1, int param2)
Definition: bind_test.cpp:95
int test_func1(const int &param1, const int &param2)
Definition: bind_test.cpp:91
Definition: ehthrow.cxx:93
void f(int n) const
Definition: bind_test.cpp:124
int m_n
Definition: bind_test.cpp:136
A()
Definition: bind_test.cpp:121
int v() const
Definition: bind_test.cpp:132
void bind2nd1()
Definition: bind_test.cpp:73
CPPUNIT_TEST(bind2nd2)
CPPUNIT_TEST_SUITE_END()
void bind2nd3()
Definition: bind_test.cpp:100
CPPUNIT_TEST(bind2nd1)
void bind2nd2()
Definition: bind_test.cpp:82
void bind1st1()
Definition: bind_test.cpp:53
CPPUNIT_TEST(bind_memfn)
void bind_memfn()
Definition: bind_test.cpp:139
CPPUNIT_TEST(bind1st1)
CPPUNIT_TEST_SUITE(BindTest)
CPPUNIT_TEST(bind2nd3)
int operator()(int &val, int incr) const
Definition: bind_test.cpp:45
int operator()(int incr, int &val) const
Definition: bind_test.cpp:39
#define CPPUNIT_CHECK(X)
Definition: cppunit_mini.h:195
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
#define _STLP_MUTABLE(type, x)
Definition: features.h:634
const GLdouble * v
Definition: gl.h:2040
GLdouble n
Definition: glext.h:7729
GLuint GLenum GLenum transform
Definition: glext.h:9407
GLuint GLfloat * val
Definition: glext.h:7180
GLfloat GLfloat p
Definition: glext.h:8902
Definition: features.h:417