aboutsummaryrefslogtreecommitdiff
path: root/stlport/stl/_function_adaptors.h
blob: 0da419b9ad241bf4698dc0b6c129a965420a2dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Copyright (c) 1996-1998
 * Silicon Graphics Computer Systems, Inc.
 *
 * Copyright (c) 1997
 * Moscow Center for SPARC Technology
 *
 * Copyright (c) 1999
 * Boris Fomitchev
 *
 * Copyright (c) 2000
 * Pavel Kuznetsov
 *
 * Copyright (c) 2001
 * Meridian'93
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

/* NOTE: This is an internal header file, included by other STL headers.
 *   You should not attempt to use it directly.
 */

// This file has noo macro protection as it is meant to be included several times
// from other header.
// Adaptor function objects: pointers to member functions.

// There are a total of 16 = 2^4 function objects in this family.
//  (1) Member functions taking no arguments vs member functions taking
//       one argument.
//  (2) Call through pointer vs call through reference.
//  (3) Member function with void return type vs member function with
//      non-void return type.
//  (4) Const vs non-const member function.

// Note that choice (3) is nothing more than a workaround: according
//  to the draft, compilers should handle void and non-void the same way.
//  This feature is not yet widely implemented, though.  You can only use
//  member functions returning void if your compiler supports partial
//  specialization.

// All of this complexity is in the function objects themselves.  You can
//  ignore it by using the helper function mem_fun and mem_fun_ref,
//  which create whichever type of adaptor is appropriate.

_STLP_BEGIN_NAMESPACE

//This implementation will only be used if needed, that is to say when there is the return void bug
//and when there is no partial template specialization
#if defined (_STLP_DONT_RETURN_VOID) && defined (_STLP_NO_CLASS_PARTIAL_SPECIALIZATION) && defined (_STLP_MEMBER_TEMPLATE_CLASSES)

template<class _Result, class _Tp>
class _Mem_fun0_ptr : public unary_function<_Tp*, _Result> {
protected:
  typedef _Result (_Tp::*__fun_type) ();
  explicit _Mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(_Tp* __p) const { return (__p->*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Result, class _Tp, class _Arg>
class _Mem_fun1_ptr : public binary_function<_Tp*,_Arg,_Result> {
protected:
  typedef _Result (_Tp::*__fun_type) (_Arg);
  explicit _Mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }

private:
  __fun_type _M_f;
};

template<class _Result, class _Tp>
class _Const_mem_fun0_ptr : public unary_function<const _Tp*,_Result> {
protected:
  typedef _Result (_Tp::*__fun_type) () const;
  explicit _Const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(const _Tp* __p) const { return (__p->*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Result, class _Tp, class _Arg>
class _Const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,_Result> {
protected:
  typedef _Result (_Tp::*__fun_type) (_Arg) const;
  explicit _Const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(const _Tp* __p, _Arg __x) const {
    return (__p->*_M_f)(__x); }

private:
  __fun_type _M_f;
};

template<class _Result, class _Tp>
class _Mem_fun0_ref : public unary_function<_Tp,_Result> {
protected:
  typedef _Result (_Tp::*__fun_type) ();
  explicit _Mem_fun0_ref(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(_Tp& __p) const { return (__p.*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Result, class _Tp, class _Arg>
class _Mem_fun1_ref : public binary_function<_Tp,_Arg,_Result> {
protected:
  typedef _Result (_Tp::*__fun_type) (_Arg);
  explicit _Mem_fun1_ref(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(_Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); }

private:
  __fun_type _M_f;
};

template<class _Result, class _Tp>
class _Const_mem_fun0_ref : public unary_function<_Tp,_Result> {
protected:
  typedef _Result (_Tp::*__fun_type) () const;
  explicit _Const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(const _Tp& __p) const { return (__p.*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Result, class _Tp, class _Arg>
class _Const_mem_fun1_ref : public binary_function<_Tp,_Arg,_Result> {
protected:
  typedef _Result (_Tp::*__fun_type) (_Arg) const;
  explicit _Const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator ()(const _Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); }

private:
  __fun_type _M_f;
};

template<class _Result>
struct _Mem_fun_traits {
  template<class _Tp>
  struct _Args0 {
    typedef _Mem_fun0_ptr<_Result,_Tp>            _Ptr;
    typedef _Const_mem_fun0_ptr<_Result,_Tp>      _Ptr_const;
    typedef _Mem_fun0_ref<_Result,_Tp>            _Ref;
    typedef _Const_mem_fun0_ref<_Result,_Tp>      _Ref_const;
  };

  template<class _Tp, class _Arg>
  struct _Args1 {
    typedef _Mem_fun1_ptr<_Result,_Tp,_Arg>       _Ptr;
    typedef _Const_mem_fun1_ptr<_Result,_Tp,_Arg> _Ptr_const;
    typedef _Mem_fun1_ref<_Result,_Tp,_Arg>       _Ref;
    typedef _Const_mem_fun1_ref<_Result,_Tp,_Arg> _Ref_const;
  };
};

template<class _Arg, class _Result>
class _Ptr_fun1_base : public unary_function<_Arg, _Result> {
protected:
  typedef _Result (*__fun_type) (_Arg);
  explicit _Ptr_fun1_base(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator()(_Arg __x) const { return _M_f(__x); }

private:
  __fun_type _M_f;
};

template <class _Arg1, class _Arg2, class _Result>
class _Ptr_fun2_base : public binary_function<_Arg1,_Arg2,_Result> {
protected:
  typedef _Result (*__fun_type) (_Arg1, _Arg2);
  explicit _Ptr_fun2_base(__fun_type __f) : _M_f(__f) {}

public:
  _Result operator()(_Arg1 __x, _Arg2 __y) const { return _M_f(__x, __y); }

private:
  __fun_type _M_f;
};

template<class _Result>
struct _Ptr_fun_traits {
  template<class _Arg> struct _Args1 {
    typedef _Ptr_fun1_base<_Arg,_Result> _Fun;
  };

  template<class _Arg1, class _Arg2> struct _Args2 {
    typedef _Ptr_fun2_base<_Arg1,_Arg2,_Result> _Fun;
  };
};

/* Specializations for void return type */
template<class _Tp>
class _Void_mem_fun0_ptr : public unary_function<_Tp*,void> {
protected:
  typedef void (_Tp::*__fun_type) ();
  explicit _Void_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(_Tp* __p) const { (__p->*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Tp, class _Arg>
class _Void_mem_fun1_ptr : public binary_function<_Tp*,_Arg,void> {
protected:
  typedef void (_Tp::*__fun_type) (_Arg);
  explicit _Void_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }

private:
  __fun_type _M_f;
};

template<class _Tp>
class _Void_const_mem_fun0_ptr : public unary_function<const _Tp*,void> {
protected:
  typedef void (_Tp::*__fun_type) () const;
  explicit _Void_const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(const _Tp* __p) const { (__p->*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Tp, class _Arg>
class _Void_const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,void> {
protected:
  typedef void (_Tp::*__fun_type) (_Arg) const;
  explicit _Void_const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }

private:
  __fun_type _M_f;
};

template<class _Tp>
class _Void_mem_fun0_ref : public unary_function<_Tp,void> {
protected:
  typedef void (_Tp::*__fun_type) ();
  explicit _Void_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(_Tp& __p) const { (__p.*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Tp, class _Arg>
class _Void_mem_fun1_ref : public binary_function<_Tp,_Arg,void> {
protected:
  typedef void (_Tp::*__fun_type) (_Arg);
  explicit _Void_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(_Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); }

private:
  __fun_type _M_f;
};

template<class _Tp>
class _Void_const_mem_fun0_ref : public unary_function<_Tp,void> {
protected:
  typedef void (_Tp::*__fun_type) () const;
  explicit _Void_const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(const _Tp& __p) const { (__p.*_M_f)(); }

private:
  __fun_type _M_f;
};

template<class _Tp, class _Arg>
class _Void_const_mem_fun1_ref : public binary_function<_Tp,_Arg,void> {
protected:
  typedef void (_Tp::*__fun_type) (_Arg) const;
  explicit _Void_const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}

public:
  void operator ()(const _Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); }

private:
  __fun_type _M_f;
};

_STLP_TEMPLATE_NULL
struct _Mem_fun_traits<void> {
  template<class _Tp> struct _Args0 {
    typedef _Void_mem_fun0_ptr<_Tp>             _Ptr;
    typedef _Void_const_mem_fun0_ptr<_Tp>       _Ptr_const;
    typedef _Void_mem_fun0_ref<_Tp>             _Ref;
    typedef _Void_const_mem_fun0_ref<_Tp>       _Ref_const;
  };

  template<class _Tp, class _Arg> struct _Args1 {
    typedef _Void_mem_fun1_ptr<_Tp,_Arg>        _Ptr;
    typedef _Void_const_mem_fun1_ptr<_Tp,_Arg>  _Ptr_const;
    typedef _Void_mem_fun1_ref<_Tp,_Arg>        _Ref;
    typedef _Void_const_mem_fun1_ref<_Tp,_Arg>  _Ref_const;
  };
};

template<class _Arg>
class _Ptr_void_fun1_base : public unary_function<_Arg, void> {
protected:
  typedef void (*__fun_type) (_Arg);
  explicit _Ptr_void_fun1_base(__fun_type __f) : _M_f(__f) {}

public:
  void operator()(_Arg __x) const { _M_f(__x); }

private:
  __fun_type _M_f;
};

template <class _Arg1, class _Arg2>
class _Ptr_void_fun2_base : public binary_function<_Arg1,_Arg2,void> {
protected:
  typedef void (*__fun_type) (_Arg1, _Arg2);
  explicit _Ptr_void_fun2_base(__fun_type __f) : _M_f(__f) {}

public:
  void operator()(_Arg1 __x, _Arg2 __y) const { _M_f(__x, __y); }

private:
  __fun_type _M_f;
};

_STLP_TEMPLATE_NULL
struct _Ptr_fun_traits<void> {
  template<class _Arg> struct _Args1 {
    typedef _Ptr_void_fun1_base<_Arg> _Fun;
  };

  template<class _Arg1, class _Arg2> struct _Args2 {
    typedef _Ptr_void_fun2_base<_Arg1,_Arg2> _Fun;
  };
};

// pavel: need extra level of inheritance here since MSVC++ does not
// accept traits-based fake partial specialization for template
// arguments other than first

template<class _Result, class _Arg>
class _Ptr_fun1 :
  public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun {
protected:
  typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun _Base;
  explicit _Ptr_fun1(typename _Base::__fun_type __f) : _Base(__f) {}
};

template<class _Result, class _Arg1, class _Arg2>
class _Ptr_fun2 :
  public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun {
protected:
  typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun _Base;
  explicit _Ptr_fun2(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp>
class mem_fun_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr _Base;
public:
  explicit mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp>
class const_mem_fun_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const _Base;
public:
  explicit const_mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp>
class mem_fun_ref_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref _Base;
public:
  explicit mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp>
class const_mem_fun_ref_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const _Base;
public:
  explicit const_mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp, class _Arg>
class mem_fun1_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr _Base;
public:
  explicit mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp, class _Arg>
class const_mem_fun1_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const _Base;
public:
  explicit const_mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp, class _Arg>
class mem_fun1_ref_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref _Base;
public:
  explicit mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Result, class _Tp, class _Arg>
class const_mem_fun1_ref_t :
  public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const {
  typedef typename
    _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const _Base;
public:
  explicit const_mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};

template <class _Arg, class _Result>
class pointer_to_unary_function :
  public _Ptr_fun1<_Result,_Arg> {
  typedef typename
    _Ptr_fun1<_Result,_Arg>::__fun_type __fun_type;
public:
  explicit pointer_to_unary_function(__fun_type __f)
    : _Ptr_fun1<_Result,_Arg>(__f) {}
};

template <class _Arg1, class _Arg2, class _Result>
class pointer_to_binary_function :
  public _Ptr_fun2<_Result,_Arg1,_Arg2> {
  typedef typename
    _Ptr_fun2<_Result,_Arg1,_Arg2>::__fun_type __fun_type;
public:
  explicit pointer_to_binary_function(__fun_type __f)
    : _Ptr_fun2<_Result,_Arg1,_Arg2>(__f) {}
};

#else

template <class _Ret, class _Tp>
class mem_fun_t : public unary_function<_Tp*,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(void);
public:
  explicit mem_fun_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Ret, class _Tp>
class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(void) const;
public:
  explicit const_mem_fun_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Ret, class _Tp>
class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(void);
public:
  explicit mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Ret, class _Tp>
class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(void) const;
public:
  explicit const_mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Ret, class _Tp, class _Arg>
class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(_Arg);
public:
  explicit mem_fun1_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(_Arg) const;
public:
  explicit const_mem_fun1_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(const _Tp* __p, _Arg __x) const
    { return (__p->*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Ret, class _Tp, class _Arg>
class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(_Arg);
public:
  explicit mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
  typedef _Ret (_Tp::*__fun_type)(_Arg) const;
public:
  explicit const_mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {}
  _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Arg, class _Result>
class pointer_to_unary_function : public unary_function<_Arg, _Result> {
protected:
  _Result (*_M_ptr)(_Arg);
public:
  pointer_to_unary_function() {}
  explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
  _Result operator()(_Arg __x) const { return _M_ptr(__x); }
};

template <class _Arg1, class _Arg2, class _Result>
class pointer_to_binary_function :
  public binary_function<_Arg1,_Arg2,_Result> {
protected:
    _Result (*_M_ptr)(_Arg1, _Arg2);
public:
    pointer_to_binary_function() {}
    explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
      : _M_ptr(__x) {}
    _Result operator()(_Arg1 __x, _Arg2 __y) const {
      return _M_ptr(__x, __y);
    }
};

#  if defined (_STLP_DONT_RETURN_VOID) && !defined (_STLP_NO_CLASS_PARTIAL_SPECIALIZATION)
//Partial specializations for the void type
template <class _Tp>
class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
  typedef void (_Tp::*__fun_type)(void);
public:
  explicit mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(_Tp* __p) const { (__p->*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Tp>
class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
  typedef void (_Tp::*__fun_type)(void) const;
public:
  explicit const_mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Tp>
class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
  typedef void (_Tp::*__fun_type)(void);
public:
  explicit mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(_Tp& __r) const { (__r.*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Tp>
class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
  typedef void (_Tp::*__fun_type)(void) const;
public:
  explicit const_mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
private:
  __fun_type _M_f;
};

template <class _Tp, class _Arg>
class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
  typedef void (_Tp::*__fun_type)(_Arg);
public:
  explicit mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Tp, class _Arg>
class const_mem_fun1_t<void, _Tp, _Arg>
  : public binary_function<const _Tp*,_Arg,void> {
  typedef void (_Tp::*__fun_type)(_Arg) const;
public:
  explicit const_mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Tp, class _Arg>
class mem_fun1_ref_t<void, _Tp, _Arg>
  : public binary_function<_Tp,_Arg,void> {
  typedef void (_Tp::*__fun_type)(_Arg);
public:
  explicit mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Tp, class _Arg>
class const_mem_fun1_ref_t<void, _Tp, _Arg>
  : public binary_function<_Tp,_Arg,void> {
  typedef void (_Tp::*__fun_type)(_Arg) const;
public:
  explicit const_mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
  void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
private:
  __fun_type _M_f;
};

template <class _Arg>
class pointer_to_unary_function<_Arg, void> : public unary_function<_Arg, void> {
  typedef void (*__fun_type)(_Arg);
  __fun_type _M_ptr;
public:
  pointer_to_unary_function() {}
  explicit pointer_to_unary_function(__fun_type __x) : _M_ptr(__x) {}
  void operator()(_Arg __x) const { _M_ptr(__x); }
};

template <class _Arg1, class _Arg2>
class pointer_to_binary_function<_Arg1, _Arg2, void> : public binary_function<_Arg1,_Arg2,void> {
  typedef void (*__fun_type)(_Arg1, _Arg2);
  __fun_type _M_ptr;
public:
  pointer_to_binary_function() {}
  explicit pointer_to_binary_function(__fun_type __x) : _M_ptr(__x) {}
  void operator()(_Arg1 __x, _Arg2 __y) const { _M_ptr(__x, __y); }
};

#  endif

#endif

#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
// Mem_fun adaptor helper functions.  There are only two:
//  mem_fun and mem_fun_ref.  (mem_fun1 and mem_fun1_ref
//  are provided for backward compatibility, but they are no longer
//  part of the C++ standard.)

template <class _Result, class _Tp>
inline mem_fun_t<_Result,_Tp>
mem_fun(_Result (_Tp::*__f)()) { return mem_fun_t<_Result,_Tp>(__f); }

template <class _Result, class _Tp>
inline const_mem_fun_t<_Result,_Tp>
mem_fun(_Result (_Tp::*__f)() const)  { return const_mem_fun_t<_Result,_Tp>(__f); }

template <class _Result, class _Tp>
inline mem_fun_ref_t<_Result,_Tp>
mem_fun_ref(_Result (_Tp::*__f)())  { return mem_fun_ref_t<_Result,_Tp>(__f); }

template <class _Result, class _Tp>
inline const_mem_fun_ref_t<_Result,_Tp>
mem_fun_ref(_Result (_Tp::*__f)() const)  { return const_mem_fun_ref_t<_Result,_Tp>(__f); }

template <class _Result, class _Tp, class _Arg>
inline mem_fun1_t<_Result,_Tp,_Arg>
mem_fun(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); }

template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_t<_Result,_Tp,_Arg>
mem_fun(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); }

template <class _Result, class _Tp, class _Arg>
inline mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }

template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }

#  if !(defined (_STLP_NO_EXTENSIONS) || defined (_STLP_NO_ANACHRONISMS))
//  mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,
//  but they are provided for backward compatibility.
template <class _Result, class _Tp, class _Arg>
inline mem_fun1_t<_Result,_Tp,_Arg>
mem_fun1(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); }

template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_t<_Result,_Tp,_Arg>
mem_fun1(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); }

template <class _Result, class _Tp, class _Arg>
inline mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun1_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }

template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun1_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }

#  endif

#endif

template <class _Arg, class _Result>
inline pointer_to_unary_function<_Arg, _Result>
ptr_fun(_Result (*__f)(_Arg))
{ return pointer_to_unary_function<_Arg, _Result>(__f); }

template <class _Arg1, class _Arg2, class _Result>
inline pointer_to_binary_function<_Arg1,_Arg2,_Result>
ptr_fun(_Result (*__f)(_Arg1, _Arg2))
{ return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f); }

_STLP_END_NAMESPACE