Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | /* |
2 | * |
||
3 | * Copyright (c) 1994 |
||
4 | * Hewlett-Packard Company |
||
5 | * |
||
6 | * Permission to use, copy, modify, distribute and sell this software |
||
7 | * and its documentation for any purpose is hereby granted without fee, |
||
8 | * provided that the above copyright notice appear in all copies and |
||
9 | * that both that copyright notice and this permission notice appear |
||
10 | * in supporting documentation. Hewlett-Packard Company makes no |
||
11 | * representations about the suitability of this software for any |
||
12 | * purpose. It is provided "as is" without express or implied warranty. |
||
13 | * |
||
14 | * |
||
15 | * Copyright (c) 1996-1998 |
||
16 | * Silicon Graphics Computer Systems, Inc. |
||
17 | * |
||
18 | * Permission to use, copy, modify, distribute and sell this software |
||
19 | * and its documentation for any purpose is hereby granted without fee, |
||
20 | * provided that the above copyright notice appear in all copies and |
||
21 | * that both that copyright notice and this permission notice appear |
||
22 | * in supporting documentation. Silicon Graphics makes no |
||
23 | * representations about the suitability of this software for any |
||
24 | * purpose. It is provided "as is" without express or implied warranty. |
||
25 | */ |
||
26 | |||
27 | /* NOTE: This is an internal header file, included by other STL headers. |
||
28 | * You should not attempt to use it directly. |
||
29 | */ |
||
30 | |||
31 | #ifndef __SGI_STL_INTERNAL_FUNCTION_H |
||
32 | #define __SGI_STL_INTERNAL_FUNCTION_H |
||
33 | |||
34 | namespace std |
||
35 | { |
||
36 | |||
37 | template |
||
38 | struct unary_function { |
||
39 | typedef _Arg argument_type; |
||
40 | typedef _Result result_type; |
||
41 | }; |
||
42 | |||
43 | template |
||
44 | struct binary_function { |
||
45 | typedef _Arg1 first_argument_type; |
||
46 | typedef _Arg2 second_argument_type; |
||
47 | typedef _Result result_type; |
||
48 | }; |
||
49 | |||
50 | template |
||
51 | struct plus : public binary_function<_Tp,_Tp,_Tp> { |
||
52 | _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } |
||
53 | }; |
||
54 | |||
55 | template |
||
56 | struct minus : public binary_function<_Tp,_Tp,_Tp> { |
||
57 | _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; } |
||
58 | }; |
||
59 | |||
60 | template |
||
61 | struct multiplies : public binary_function<_Tp,_Tp,_Tp> { |
||
62 | _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; } |
||
63 | }; |
||
64 | |||
65 | template |
||
66 | struct divides : public binary_function<_Tp,_Tp,_Tp> { |
||
67 | _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; } |
||
68 | }; |
||
69 | |||
70 | // identity_element (not part of the C++ standard). |
||
71 | |||
72 | template |
||
73 | return _Tp(0); |
||
74 | } |
||
75 | template |
||
76 | return _Tp(1); |
||
77 | } |
||
78 | |||
79 | template |
||
80 | struct modulus : public binary_function<_Tp,_Tp,_Tp> |
||
81 | { |
||
82 | _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; } |
||
83 | }; |
||
84 | |||
85 | template |
||
86 | struct negate : public unary_function<_Tp,_Tp> |
||
87 | { |
||
88 | _Tp operator()(const _Tp& __x) const { return -__x; } |
||
89 | }; |
||
90 | |||
91 | template |
||
92 | struct equal_to : public binary_function<_Tp,_Tp,bool> |
||
93 | { |
||
94 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; } |
||
95 | }; |
||
96 | |||
97 | template |
||
98 | struct not_equal_to : public binary_function<_Tp,_Tp,bool> |
||
99 | { |
||
100 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; } |
||
101 | }; |
||
102 | |||
103 | template |
||
104 | struct greater : public binary_function<_Tp,_Tp,bool> |
||
105 | { |
||
106 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; } |
||
107 | }; |
||
108 | |||
109 | template |
||
110 | struct less : public binary_function<_Tp,_Tp,bool> |
||
111 | { |
||
112 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; } |
||
113 | }; |
||
114 | |||
115 | template |
||
116 | struct greater_equal : public binary_function<_Tp,_Tp,bool> |
||
117 | { |
||
118 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; } |
||
119 | }; |
||
120 | |||
121 | template |
||
122 | struct less_equal : public binary_function<_Tp,_Tp,bool> |
||
123 | { |
||
124 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; } |
||
125 | }; |
||
126 | |||
127 | template |
||
128 | struct logical_and : public binary_function<_Tp,_Tp,bool> |
||
129 | { |
||
130 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; } |
||
131 | }; |
||
132 | |||
133 | template |
||
134 | struct logical_or : public binary_function<_Tp,_Tp,bool> |
||
135 | { |
||
136 | bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; } |
||
137 | }; |
||
138 | |||
139 | template |
||
140 | struct logical_not : public unary_function<_Tp,bool> |
||
141 | { |
||
142 | bool operator()(const _Tp& __x) const { return !__x; } |
||
143 | }; |
||
144 | |||
145 | template |
||
146 | class unary_negate |
||
147 | : public unary_function |
||
148 | protected: |
||
149 | _Predicate _M_pred; |
||
150 | public: |
||
151 | explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {} |
||
152 | bool operator()(const typename _Predicate::argument_type& __x) const { |
||
153 | return !_M_pred(__x); |
||
154 | } |
||
155 | }; |
||
156 | |||
157 | template |
||
158 | inline unary_negate<_Predicate> |
||
159 | not1(const _Predicate& __pred) |
||
160 | { |
||
161 | return unary_negate<_Predicate>(__pred); |
||
162 | } |
||
163 | |||
164 | template |
||
165 | class binary_negate |
||
166 | : public binary_function |
||
167 | typename _Predicate::second_argument_type, |
||
168 | bool> { |
||
169 | protected: |
||
170 | _Predicate _M_pred; |
||
171 | public: |
||
172 | explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {} |
||
173 | bool operator()(const typename _Predicate::first_argument_type& __x, |
||
174 | const typename _Predicate::second_argument_type& __y) const |
||
175 | { |
||
176 | return !_M_pred(__x, __y); |
||
177 | } |
||
178 | }; |
||
179 | |||
180 | template |
||
181 | inline binary_negate<_Predicate> |
||
182 | not2(const _Predicate& __pred) |
||
183 | { |
||
184 | return binary_negate<_Predicate>(__pred); |
||
185 | } |
||
186 | |||
187 | template |
||
188 | class binder1st |
||
189 | : public unary_function |
||
190 | typename _Operation::result_type> { |
||
191 | protected: |
||
192 | _Operation op; |
||
193 | typename _Operation::first_argument_type value; |
||
194 | public: |
||
195 | binder1st(const _Operation& __x, |
||
196 | const typename _Operation::first_argument_type& __y) |
||
197 | : op(__x), value(__y) {} |
||
198 | typename _Operation::result_type |
||
199 | operator()(const typename _Operation::second_argument_type& __x) const { |
||
200 | return op(value, __x); |
||
201 | } |
||
202 | #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS |
||
203 | // 109. Missing binders for non-const sequence elements |
||
204 | typename _Operation::result_type |
||
205 | operator()(typename _Operation::second_argument_type& __x) const { |
||
206 | return op(value, __x); |
||
207 | } |
||
208 | #endif |
||
209 | }; |
||
210 | |||
211 | template |
||
212 | inline binder1st<_Operation> |
||
213 | bind1st(const _Operation& __fn, const _Tp& __x) |
||
214 | { |
||
215 | typedef typename _Operation::first_argument_type _Arg1_type; |
||
216 | return binder1st<_Operation>(__fn, _Arg1_type(__x)); |
||
217 | } |
||
218 | |||
219 | template |
||
220 | class binder2nd |
||
221 | : public unary_function |
||
222 | typename _Operation::result_type> { |
||
223 | protected: |
||
224 | _Operation op; |
||
225 | typename _Operation::second_argument_type value; |
||
226 | public: |
||
227 | binder2nd(const _Operation& __x, |
||
228 | const typename _Operation::second_argument_type& __y) |
||
229 | : op(__x), value(__y) {} |
||
230 | typename _Operation::result_type |
||
231 | operator()(const typename _Operation::first_argument_type& __x) const { |
||
232 | return op(__x, value); |
||
233 | } |
||
234 | #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS |
||
235 | // 109. Missing binders for non-const sequence elements |
||
236 | typename _Operation::result_type |
||
237 | operator()(typename _Operation::first_argument_type& __x) const { |
||
238 | return op(__x, value); |
||
239 | } |
||
240 | #endif |
||
241 | }; |
||
242 | |||
243 | template |
||
244 | inline binder2nd<_Operation> |
||
245 | bind2nd(const _Operation& __fn, const _Tp& __x) |
||
246 | { |
||
247 | typedef typename _Operation::second_argument_type _Arg2_type; |
||
248 | return binder2nd<_Operation>(__fn, _Arg2_type(__x)); |
||
249 | } |
||
250 | |||
251 | // unary_compose and binary_compose (extensions, not part of the standard). |
||
252 | |||
253 | template |
||
254 | class unary_compose |
||
255 | : public unary_function |
||
256 | typename _Operation1::result_type> |
||
257 | { |
||
258 | protected: |
||
259 | _Operation1 _M_fn1; |
||
260 | _Operation2 _M_fn2; |
||
261 | public: |
||
262 | unary_compose(const _Operation1& __x, const _Operation2& __y) |
||
263 | : _M_fn1(__x), _M_fn2(__y) {} |
||
264 | typename _Operation1::result_type |
||
265 | operator()(const typename _Operation2::argument_type& __x) const { |
||
266 | return _M_fn1(_M_fn2(__x)); |
||
267 | } |
||
268 | }; |
||
269 | |||
270 | template |
||
271 | inline unary_compose<_Operation1,_Operation2> |
||
272 | compose1(const _Operation1& __fn1, const _Operation2& __fn2) |
||
273 | { |
||
274 | return unary_compose<_Operation1,_Operation2>(__fn1, __fn2); |
||
275 | } |
||
276 | |||
277 | template |
||
278 | class binary_compose |
||
279 | : public unary_function |
||
280 | typename _Operation1::result_type> { |
||
281 | protected: |
||
282 | _Operation1 _M_fn1; |
||
283 | _Operation2 _M_fn2; |
||
284 | _Operation3 _M_fn3; |
||
285 | public: |
||
286 | binary_compose(const _Operation1& __x, const _Operation2& __y, |
||
287 | const _Operation3& __z) |
||
288 | : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { } |
||
289 | typename _Operation1::result_type |
||
290 | operator()(const typename _Operation2::argument_type& __x) const { |
||
291 | return _M_fn1(_M_fn2(__x), _M_fn3(__x)); |
||
292 | } |
||
293 | }; |
||
294 | |||
295 | template |
||
296 | inline binary_compose<_Operation1, _Operation2, _Operation3> |
||
297 | compose2(const _Operation1& __fn1, const _Operation2& __fn2, |
||
298 | const _Operation3& __fn3) |
||
299 | { |
||
300 | return binary_compose<_Operation1,_Operation2,_Operation3> |
||
301 | (__fn1, __fn2, __fn3); |
||
302 | } |
||
303 | |||
304 | template |
||
305 | class pointer_to_unary_function : public unary_function<_Arg, _Result> { |
||
306 | protected: |
||
307 | _Result (*_M_ptr)(_Arg); |
||
308 | public: |
||
309 | pointer_to_unary_function() {} |
||
310 | explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {} |
||
311 | _Result operator()(_Arg __x) const { return _M_ptr(__x); } |
||
312 | }; |
||
313 | |||
314 | template |
||
315 | inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg)) |
||
316 | { |
||
317 | return pointer_to_unary_function<_Arg, _Result>(__x); |
||
318 | } |
||
319 | |||
320 | template |
||
321 | class pointer_to_binary_function : |
||
322 | public binary_function<_Arg1,_Arg2,_Result> { |
||
323 | protected: |
||
324 | _Result (*_M_ptr)(_Arg1, _Arg2); |
||
325 | public: |
||
326 | pointer_to_binary_function() {} |
||
327 | explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2)) |
||
328 | : _M_ptr(__x) {} |
||
329 | _Result operator()(_Arg1 __x, _Arg2 __y) const { |
||
330 | return _M_ptr(__x, __y); |
||
331 | } |
||
332 | }; |
||
333 | |||
334 | template |
||
335 | inline pointer_to_binary_function<_Arg1,_Arg2,_Result> |
||
336 | ptr_fun(_Result (*__x)(_Arg1, _Arg2)) { |
||
337 | return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x); |
||
338 | } |
||
339 | |||
340 | // identity is an extensions: it is not part of the standard. |
||
341 | template |
||
342 | struct _Identity : public unary_function<_Tp,_Tp> { |
||
343 | _Tp& operator()(_Tp& __x) const { return __x; } |
||
344 | const _Tp& operator()(const _Tp& __x) const { return __x; } |
||
345 | }; |
||
346 | |||
347 | template |
||
348 | |||
349 | // select1st and select2nd are extensions: they are not part of the standard. |
||
350 | template |
||
351 | struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> { |
||
352 | typename _Pair::first_type& operator()(_Pair& __x) const { |
||
353 | return __x.first; |
||
354 | } |
||
355 | const typename _Pair::first_type& operator()(const _Pair& __x) const { |
||
356 | return __x.first; |
||
357 | } |
||
358 | }; |
||
359 | |||
360 | template |
||
361 | struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type> |
||
362 | { |
||
363 | typename _Pair::second_type& operator()(_Pair& __x) const { |
||
364 | return __x.second; |
||
365 | } |
||
366 | const typename _Pair::second_type& operator()(const _Pair& __x) const { |
||
367 | return __x.second; |
||
368 | } |
||
369 | }; |
||
370 | |||
371 | template |
||
372 | template |
||
373 | |||
374 | // project1st and project2nd are extensions: they are not part of the standard |
||
375 | template |
||
376 | struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> { |
||
377 | _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; } |
||
378 | }; |
||
379 | |||
380 | template |
||
381 | struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> { |
||
382 | _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; } |
||
383 | }; |
||
384 | |||
385 | template |
||
386 | struct project1st : public _Project1st<_Arg1, _Arg2> {}; |
||
387 | |||
388 | template |
||
389 | struct project2nd : public _Project2nd<_Arg1, _Arg2> {}; |
||
390 | |||
391 | // constant_void_fun, constant_unary_fun, and constant_binary_fun are |
||
392 | // extensions: they are not part of the standard. (The same, of course, |
||
393 | // is true of the helper functions constant0, constant1, and constant2.) |
||
394 | |||
395 | template |
||
396 | struct _Constant_void_fun { |
||
397 | typedef _Result result_type; |
||
398 | result_type _M_val; |
||
399 | |||
400 | _Constant_void_fun(const result_type& __v) : _M_val(__v) {} |
||
401 | const result_type& operator()() const { return _M_val; } |
||
402 | }; |
||
403 | |||
404 | template |
||
405 | struct _Constant_unary_fun { |
||
406 | typedef _Argument argument_type; |
||
407 | typedef _Result result_type; |
||
408 | result_type _M_val; |
||
409 | |||
410 | _Constant_unary_fun(const result_type& __v) : _M_val(__v) {} |
||
411 | const result_type& operator()(const _Argument&) const { return _M_val; } |
||
412 | }; |
||
413 | |||
414 | template |
||
415 | struct _Constant_binary_fun { |
||
416 | typedef _Arg1 first_argument_type; |
||
417 | typedef _Arg2 second_argument_type; |
||
418 | typedef _Result result_type; |
||
419 | _Result _M_val; |
||
420 | |||
421 | _Constant_binary_fun(const _Result& __v) : _M_val(__v) {} |
||
422 | const result_type& operator()(const _Arg1&, const _Arg2&) const { |
||
423 | return _M_val; |
||
424 | } |
||
425 | }; |
||
426 | |||
427 | template |
||
428 | struct constant_void_fun : public _Constant_void_fun<_Result> { |
||
429 | constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {} |
||
430 | }; |
||
431 | |||
432 | |||
433 | template |
||
434 | class _Argument = _Result> |
||
435 | struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument> |
||
436 | { |
||
437 | constant_unary_fun(const _Result& __v) |
||
438 | : _Constant_unary_fun<_Result, _Argument>(__v) {} |
||
439 | }; |
||
440 | |||
441 | |||
442 | template |
||
443 | class _Arg1 = _Result, |
||
444 | class _Arg2 = _Arg1> |
||
445 | struct constant_binary_fun |
||
446 | : public _Constant_binary_fun<_Result, _Arg1, _Arg2> |
||
447 | { |
||
448 | constant_binary_fun(const _Result& __v) |
||
449 | : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {} |
||
450 | }; |
||
451 | |||
452 | template |
||
453 | inline constant_void_fun<_Result> constant0(const _Result& __val) |
||
454 | { |
||
455 | return constant_void_fun<_Result>(__val); |
||
456 | } |
||
457 | |||
458 | template |
||
459 | inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val) |
||
460 | { |
||
461 | return constant_unary_fun<_Result,_Result>(__val); |
||
462 | } |
||
463 | |||
464 | template |
||
465 | inline constant_binary_fun<_Result,_Result,_Result> |
||
466 | constant2(const _Result& __val) |
||
467 | { |
||
468 | return constant_binary_fun<_Result,_Result,_Result>(__val); |
||
469 | } |
||
470 | |||
471 | // subtractive_rng is an extension: it is not part of the standard. |
||
472 | // Note: this code assumes that int is 32 bits. |
||
473 | class subtractive_rng : public unary_function |
||
474 | private: |
||
475 | unsigned int _M_table[55]; |
||
476 | size_t _M_index1; |
||
477 | size_t _M_index2; |
||
478 | public: |
||
479 | unsigned int operator()(unsigned int __limit) { |
||
480 | _M_index1 = (_M_index1 + 1) % 55; |
||
481 | _M_index2 = (_M_index2 + 1) % 55; |
||
482 | _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2]; |
||
483 | return _M_table[_M_index1] % __limit; |
||
484 | } |
||
485 | |||
486 | void _M_initialize(unsigned int __seed) |
||
487 | { |
||
488 | unsigned int __k = 1; |
||
489 | _M_table[54] = __seed; |
||
490 | size_t __i; |
||
491 | for (__i = 0; __i < 54; __i++) { |
||
492 | size_t __ii = (21 * (__i + 1) % 55) - 1; |
||
493 | _M_table[__ii] = __k; |
||
494 | __k = __seed - __k; |
||
495 | __seed = _M_table[__ii]; |
||
496 | } |
||
497 | for (int __loop = 0; __loop < 4; __loop++) { |
||
498 | for (__i = 0; __i < 55; __i++) |
||
499 | _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55]; |
||
500 | } |
||
501 | _M_index1 = 0; |
||
502 | _M_index2 = 31; |
||
503 | } |
||
504 | |||
505 | subtractive_rng(unsigned int __seed) { _M_initialize(__seed); } |
||
506 | subtractive_rng() { _M_initialize(161803398u); } |
||
507 | }; |
||
508 | |||
509 | |||
510 | // Adaptor function objects: pointers to member functions. |
||
511 | |||
512 | // There are a total of 16 = 2^4 function objects in this family. |
||
513 | // (1) Member functions taking no arguments vs member functions taking |
||
514 | // one argument. |
||
515 | // (2) Call through pointer vs call through reference. |
||
516 | // (3) Member function with void return type vs member function with |
||
517 | // non-void return type. |
||
518 | // (4) Const vs non-const member function. |
||
519 | |||
520 | // Note that choice (3) is nothing more than a workaround: according |
||
521 | // to the draft, compilers should handle void and non-void the same way. |
||
522 | // This feature is not yet widely implemented, though. You can only use |
||
523 | // member functions returning void if your compiler supports partial |
||
524 | // specialization. |
||
525 | |||
526 | // All of this complexity is in the function objects themselves. You can |
||
527 | // ignore it by using the helper function mem_fun and mem_fun_ref, |
||
528 | // which create whichever type of adaptor is appropriate. |
||
529 | // (mem_fun1 and mem_fun1_ref are no longer part of the C++ standard, |
||
530 | // but they are provided for backward compatibility.) |
||
531 | |||
532 | |||
533 | template |
||
534 | class mem_fun_t : public unary_function<_Tp*,_Ret> { |
||
535 | public: |
||
536 | explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {} |
||
537 | _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); } |
||
538 | private: |
||
539 | _Ret (_Tp::*_M_f)(); |
||
540 | }; |
||
541 | |||
542 | template |
||
543 | class const_mem_fun_t : public unary_function |
||
544 | public: |
||
545 | explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {} |
||
546 | _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); } |
||
547 | private: |
||
548 | _Ret (_Tp::*_M_f)() const; |
||
549 | }; |
||
550 | |||
551 | |||
552 | template |
||
553 | class mem_fun_ref_t : public unary_function<_Tp,_Ret> { |
||
554 | public: |
||
555 | explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {} |
||
556 | _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); } |
||
557 | private: |
||
558 | _Ret (_Tp::*_M_f)(); |
||
559 | }; |
||
560 | |||
561 | template |
||
562 | class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> { |
||
563 | public: |
||
564 | explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {} |
||
565 | _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); } |
||
566 | private: |
||
567 | _Ret (_Tp::*_M_f)() const; |
||
568 | }; |
||
569 | |||
570 | template |
||
571 | class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> { |
||
572 | public: |
||
573 | explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {} |
||
574 | _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); } |
||
575 | private: |
||
576 | _Ret (_Tp::*_M_f)(_Arg); |
||
577 | }; |
||
578 | |||
579 | template |
||
580 | class const_mem_fun1_t : public binary_function |
||
581 | public: |
||
582 | explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} |
||
583 | _Ret operator()(const _Tp* __p, _Arg __x) const |
||
584 | { return (__p->*_M_f)(__x); } |
||
585 | private: |
||
586 | _Ret (_Tp::*_M_f)(_Arg) const; |
||
587 | }; |
||
588 | |||
589 | template |
||
590 | class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> { |
||
591 | public: |
||
592 | explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {} |
||
593 | _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } |
||
594 | private: |
||
595 | _Ret (_Tp::*_M_f)(_Arg); |
||
596 | }; |
||
597 | |||
598 | template |
||
599 | class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> { |
||
600 | public: |
||
601 | explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} |
||
602 | _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } |
||
603 | private: |
||
604 | _Ret (_Tp::*_M_f)(_Arg) const; |
||
605 | }; |
||
606 | |||
607 | template |
||
608 | class mem_fun_t |
||
609 | public: |
||
610 | explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {} |
||
611 | void operator()(_Tp* __p) const { (__p->*_M_f)(); } |
||
612 | private: |
||
613 | void (_Tp::*_M_f)(); |
||
614 | }; |
||
615 | |||
616 | template |
||
617 | class const_mem_fun_t |
||
618 | public: |
||
619 | explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {} |
||
620 | void operator()(const _Tp* __p) const { (__p->*_M_f)(); } |
||
621 | private: |
||
622 | void (_Tp::*_M_f)() const; |
||
623 | }; |
||
624 | |||
625 | template |
||
626 | class mem_fun_ref_t |
||
627 | public: |
||
628 | explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {} |
||
629 | void operator()(_Tp& __r) const { (__r.*_M_f)(); } |
||
630 | private: |
||
631 | void (_Tp::*_M_f)(); |
||
632 | }; |
||
633 | |||
634 | template |
||
635 | class const_mem_fun_ref_t |
||
636 | public: |
||
637 | explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {} |
||
638 | void operator()(const _Tp& __r) const { (__r.*_M_f)(); } |
||
639 | private: |
||
640 | void (_Tp::*_M_f)() const; |
||
641 | }; |
||
642 | |||
643 | template |
||
644 | class mem_fun1_t |
||
645 | public: |
||
646 | explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {} |
||
647 | void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } |
||
648 | private: |
||
649 | void (_Tp::*_M_f)(_Arg); |
||
650 | }; |
||
651 | |||
652 | template |
||
653 | class const_mem_fun1_t |
||
654 | : public binary_function |
||
655 | public: |
||
656 | explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} |
||
657 | void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } |
||
658 | private: |
||
659 | void (_Tp::*_M_f)(_Arg) const; |
||
660 | }; |
||
661 | |||
662 | template |
||
663 | class mem_fun1_ref_t |
||
664 | : public binary_function<_Tp,_Arg,void> { |
||
665 | public: |
||
666 | explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {} |
||
667 | void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } |
||
668 | private: |
||
669 | void (_Tp::*_M_f)(_Arg); |
||
670 | }; |
||
671 | |||
672 | template |
||
673 | class const_mem_fun1_ref_t |
||
674 | : public binary_function<_Tp,_Arg,void> { |
||
675 | public: |
||
676 | explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} |
||
677 | void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } |
||
678 | private: |
||
679 | void (_Tp::*_M_f)(_Arg) const; |
||
680 | }; |
||
681 | |||
682 | |||
683 | // Mem_fun adaptor helper functions. There are only two: |
||
684 | // mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref |
||
685 | // are provided for backward compatibility, but they are no longer |
||
686 | // part of the C++ standard.) |
||
687 | |||
688 | template |
||
689 | inline mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)()) |
||
690 | { return mem_fun_t<_Ret,_Tp>(__f); } |
||
691 | |||
692 | template |
||
693 | inline const_mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)() const) |
||
694 | { return const_mem_fun_t<_Ret,_Tp>(__f); } |
||
695 | |||
696 | template |
||
697 | inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)()) |
||
698 | { return mem_fun_ref_t<_Ret,_Tp>(__f); } |
||
699 | |||
700 | template |
||
701 | inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const) |
||
702 | { return const_mem_fun_ref_t<_Ret,_Tp>(__f); } |
||
703 | |||
704 | template |
||
705 | inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg)) |
||
706 | { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); } |
||
707 | |||
708 | template |
||
709 | inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg) const) |
||
710 | { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); } |
||
711 | |||
712 | template |
||
713 | inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref(_Ret (_Tp::*__f)(_Arg)) |
||
714 | { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); } |
||
715 | |||
716 | template |
||
717 | inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg> |
||
718 | mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const) |
||
719 | { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); } |
||
720 | |||
721 | template |
||
722 | inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg)) |
||
723 | { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); } |
||
724 | |||
725 | template |
||
726 | inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg) const) |
||
727 | { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); } |
||
728 | |||
729 | template |
||
730 | inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun1_ref(_Ret (_Tp::*__f)(_Arg)) |
||
731 | { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); } |
||
732 | |||
733 | template |
||
734 | inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg> |
||
735 | mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const) |
||
736 | { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); } |
||
737 | |||
738 | } // namespace std |
||
739 | |||
740 | #endif /* __SGI_STL_INTERNAL_FUNCTION_H */ |
||
741 | |||
742 | // Local Variables: |
||
743 | // mode:C++ |
||
744 | // End:>>>=>> |