1
 
/*      Copyright (C) 2004 Garrett A. Kajmowicz
 
2
 
        This file is part of the uClibc++ Library.
 
3
 
        This library is free software; you can redistribute it and/or
 
4
 
        modify it under the terms of the GNU Lesser General Public
 
5
 
        License as published by the Free Software Foundation; either
 
6
 
        version 2.1 of the License, or (at your option) any later version.
 
8
 
        This library is distributed in the hope that it will be useful,
 
9
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 
        Lesser General Public License for more details.
 
13
 
        You should have received a copy of the GNU Lesser General Public
 
14
 
        License along with this library; if not, write to the Free Software
 
15
 
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
#ifndef __STD_HEADER_FUNCTIONAL
 
20
 
#define __STD_HEADER_FUNCTIONAL 1
 
22
 
#include <basic_definitions>
 
24
 
#pragma GCC visibility push(default)
 
28
 
        template <class Arg, class Result> struct unary_function;
 
29
 
        template <class Arg1, class Arg2, class Result> struct binary_function;
 
31
 
        template <class T> struct plus;
 
32
 
        template <class T> struct minus;
 
33
 
        template <class T> struct multiplies;
 
34
 
        template <class T> struct divides;
 
35
 
        template <class T> struct modulus;
 
36
 
        template <class T> struct negate;
 
38
 
        template <class T> struct equal_to;
 
39
 
        template <class T> struct not_equal_to;
 
40
 
        template <class T> struct greater;
 
41
 
        template <class T> struct less;
 
42
 
        template <class T> struct greater_equal;
 
43
 
        template <class T> struct less_equal;
 
45
 
        template <class T> struct logical_and;
 
46
 
        template <class T> struct logical_or;
 
47
 
        template <class T> struct logical_not;
 
49
 
        template <class Predicate> struct unary_negate;
 
50
 
        template <class Predicate> unary_negate<Predicate>  not1(const Predicate&);
 
51
 
        template <class Predicate> struct binary_negate;
 
52
 
        template <class Predicate> binary_negate<Predicate> not2(const Predicate&);
 
55
 
        template <class Operation> class binder1st;
 
56
 
        template <class Operation, class T> binder1st<Operation> bind1st(const Operation&, const T&);
 
57
 
        template <class Operation> class binder2nd;
 
58
 
        template <class Operation, class T> binder2nd<Operation> bind2nd(const Operation&, const T&);
 
60
 
        template <class Arg, class Result> class pointer_to_unary_function;
 
61
 
        template <class Arg, class Result> pointer_to_unary_function<Arg,Result> ptr_fun(Result (*)(Arg));
 
62
 
        template <class Arg1, class Arg2, class Result> class pointer_to_binary_function;
 
63
 
        template <class Arg1, class Arg2, class Result> 
 
64
 
                pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*)(Arg1,Arg2));
 
66
 
        template<class S, class T> class mem_fun_t;
 
67
 
        template<class S, class T, class A> class mem_fun1_t;
 
68
 
        template<class S, class T> class const_mem_fun_t;
 
69
 
        template<class S, class T, class A> class const_mem_fun1_t;
 
70
 
        template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
 
71
 
        template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
 
72
 
        template<class S, class T> class mem_fun_ref_t;
 
73
 
        template<class S, class T, class A> class mem_fun1_ref_t;
 
74
 
        template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
 
75
 
        template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun1_ref(S (T::*f)(A));
 
79
 
        template <class Arg, class Result> struct _UCXXEXPORT unary_function{
 
80
 
                typedef Arg argument_type;
 
81
 
                typedef Result result_type;
 
85
 
        template <class Arg1, class Arg2, class Result> struct _UCXXEXPORT binary_function{
 
86
 
                typedef Arg1   first_argument_type;
 
87
 
                typedef Arg2   second_argument_type;
 
88
 
                typedef Result result_type;
 
91
 
        template <class T> struct _UCXXEXPORT plus : binary_function<T,T,T>{
 
92
 
                T operator()(const T& x, const T& y) const{
 
97
 
        template <class T> struct _UCXXEXPORT minus : binary_function<T,T,T>{
 
98
 
                T operator()(const T& x, const T& y) const{
 
103
 
        template <class T> struct _UCXXEXPORT multiplies : binary_function<T,T,T>{
 
104
 
                T operator()(const T& x, const T& y) const{
 
109
 
        template <class T> struct _UCXXEXPORT divides : binary_function<T,T,T>{
 
110
 
                T operator()(const T& x, const T& y) const{
 
115
 
        template <class T> struct _UCXXEXPORT modulus : binary_function<T,T,T>{
 
116
 
                T operator()(const T& x, const T& y) const{
 
121
 
        template <class T> struct _UCXXEXPORT negate : unary_function<T,T>{
 
122
 
                T operator()(const T& x) const{
 
127
 
        template <class T> struct _UCXXEXPORT equal_to : binary_function<T,T,bool>{
 
128
 
                bool operator()(const T& x, const T& y) const{
 
133
 
        template <class T> struct _UCXXEXPORT not_equal_to : binary_function<T,T,bool>{
 
134
 
                bool operator()(const T& x, const T& y) const{
 
139
 
        template <class T> struct _UCXXEXPORT greater : binary_function<T,T,bool>{
 
140
 
                bool operator()(const T& x, const T& y) const{
 
145
 
        template <class T> struct _UCXXEXPORT less : binary_function<T,T,bool>{
 
146
 
                bool operator()(const T& x, const T& y) const{
 
151
 
        template <class T> struct _UCXXEXPORT greater_equal : binary_function<T,T,bool>{
 
152
 
                bool operator()(const T& x, const T& y) const{
 
157
 
        template <class T> struct _UCXXEXPORT less_equal : binary_function<T,T,bool>{
 
158
 
                bool operator()(const T& x, const T& y) const{
 
163
 
        template <class T> struct _UCXXEXPORT logical_and : binary_function<T,T,bool> {
 
164
 
                bool operator()(const T& x, const T& y) const{
 
169
 
        template <class T> struct _UCXXEXPORT logical_or : binary_function<T,T,bool> {
 
170
 
                bool operator()(const T& x, const T& y) const{
 
175
 
        template <class T> struct _UCXXEXPORT logical_not : unary_function<T,bool> {
 
176
 
                bool operator()(const T& x) const{
 
181
 
        template <class Predicate> class _UCXXEXPORT unary_negate
 
182
 
                : public unary_function<typename Predicate::argument_type,bool>
 
185
 
                explicit unary_negate(const Predicate& pred) : p(pred) {  }
 
186
 
                bool operator()(const typename Predicate::argument_type& x) const{
 
194
 
        template <class Predicate> _UCXXEXPORT unary_negate<Predicate> not1(const Predicate& pred){
 
195
 
                return unary_negate<Predicate>(pred);
 
199
 
        template <class Predicate> class _UCXXEXPORT binary_negate : public
 
200
 
                binary_function<typename Predicate::first_argument_type,
 
201
 
                        typename Predicate::second_argument_type, bool>
 
204
 
                explicit binary_negate(const Predicate& pred) : p(pred) {  }
 
205
 
                bool operator()(const typename Predicate::first_argument_type& x,
 
206
 
                        const typename Predicate::second_argument_type& y) const
 
215
 
        template <class Predicate> _UCXXEXPORT binary_negate<Predicate> not2(const Predicate& pred){
 
216
 
                return binary_negate<Predicate>(pred);
 
220
 
        template <class Operation> class _UCXXEXPORT binder1st
 
221
 
                : public unary_function<typename Operation::second_argument_type, 
 
222
 
                        typename Operation::result_type>
 
226
 
                typename Operation::first_argument_type value;
 
228
 
                binder1st(const Operation& x, const typename Operation::first_argument_type& y) : op(x), value(y){  }
 
229
 
                typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const{
 
235
 
        template <class Operation, class T> _UCXXEXPORT binder1st<Operation> bind1st(const Operation& op, const T& x){
 
236
 
                return binder1st<Operation>(op, typename Operation::first_argument_type(x));
 
240
 
        template <class Operation> class _UCXXEXPORT binder2nd
 
241
 
                : public unary_function<typename Operation::first_argument_type,
 
242
 
                        typename Operation::result_type>
 
246
 
                typename Operation::second_argument_type value;
 
248
 
                binder2nd(const Operation& x, const typename Operation::second_argument_type& y) : op(x), value(y) {  }
 
249
 
                typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const{
 
255
 
        template <class Operation, class T> _UCXXEXPORT 
 
256
 
                binder2nd<Operation> bind2nd(const Operation& op, const T& x)
 
258
 
                return binder2nd<Operation>(op, typename Operation::second_argument_type(x));
 
262
 
        template <class Arg, class Result> class _UCXXEXPORT 
 
263
 
                pointer_to_unary_function : public unary_function<Arg, Result>
 
268
 
                explicit pointer_to_unary_function(Result (*f)(Arg)) : func(f) {  }
 
269
 
                Result operator()(Arg x) const{
 
275
 
        template <class Arg, class Result> _UCXXEXPORT pointer_to_unary_function<Arg, Result> ptr_fun(Result (*f)(Arg)){
 
276
 
                return pointer_to_unary_function<Arg, Result>(f);
 
280
 
        template <class Arg1, class Arg2, class Result> class _UCXXEXPORT 
 
281
 
                pointer_to_binary_function : public binary_function<Arg1,Arg2,Result>
 
284
 
                Result (*func)(Arg1, Arg2);
 
286
 
                explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)) : func(f) {  }
 
287
 
                Result operator()(Arg1 x, Arg2 y) const{
 
292
 
        template <class Arg1, class Arg2, class Result> _UCXXEXPORT 
 
293
 
                pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1, Arg2))
 
295
 
                return pointer_to_binary_function<Arg1,Arg2,Result>(f);
 
299
 
        template <class S, class T> class _UCXXEXPORT mem_fun_t
 
300
 
                : public unary_function<T*, S>
 
303
 
                explicit mem_fun_t(S (T::*p)()) : m(p) {  }
 
304
 
                S operator()(T* p) const { return (p->*m)(); }
 
310
 
        template <class S, class T, class A> class _UCXXEXPORT mem_fun1_t
 
311
 
                : public binary_function<T*, A, S>
 
314
 
                explicit mem_fun1_t(S (T::*p)(A)) : m(p) {  }
 
315
 
                S operator()(T* p, A x) const { return (p->*m)(x); }
 
321
 
        template <class S, class T> class _UCXXEXPORT const_mem_fun_t
 
322
 
                : public unary_function<const T*, S>
 
325
 
                explicit const_mem_fun_t(S (T::*p)() const) : m(p) {  }
 
326
 
                S operator()(const T* p) const { return (p->*m)(); }
 
332
 
        template <class S, class T, class A> class _UCXXEXPORT const_mem_fun1_t
 
333
 
                : public binary_function<T*, A, S>
 
336
 
                explicit const_mem_fun1_t(S (T::*p)(A) const) : m(p) {  }
 
337
 
                S operator()(const T* p, A x) const { return (p->*m)(x); }
 
343
 
        template<class S, class T> _UCXXEXPORT mem_fun_t<S,T> mem_fun(S (T::*f)()){
 
344
 
                return mem_fun_t<S, T>(f);
 
347
 
        template<class S, class T> _UCXXEXPORT const_mem_fun_t<S,T> mem_fun(S (T::*f)() const){
 
348
 
                return const_mem_fun_t<S, T>(f);
 
351
 
        template<class S, class T, class A> _UCXXEXPORT mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)){
 
352
 
                return mem_fun1_t<S, T, A>(f);
 
355
 
        template<class S, class T, class A> _UCXXEXPORT const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const){
 
356
 
                return const_mem_fun1_t<S, T, A>(f);
 
359
 
        template <class S, class T> class _UCXXEXPORT mem_fun_ref_t
 
360
 
                : public unary_function<T, S>
 
363
 
                explicit mem_fun_ref_t(S (T::*p)()) : mf(p) {  }
 
364
 
                S operator()(T& p) { return (p.*mf)(); } 
 
369
 
        template <class S, class T, class A> class _UCXXEXPORT mem_fun1_ref_t
 
370
 
                : public binary_function<T, A, S>
 
373
 
                explicit mem_fun1_ref_t(S (T::*p)(A)) : mf(p) {  }
 
374
 
                S operator()(T& p, A x) { return (p.*mf)(x); }
 
379
 
        template<class S, class T> _UCXXEXPORT mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()){
 
380
 
                return mem_fun_ref_t<S,T>(f);
 
383
 
        template<class S, class T, class A> _UCXXEXPORT mem_fun1_ref_t<S,T,A> mem_fun1_ref(S (T::*f)(A)){
 
384
 
                return mem_fun1_ref_t<S,T,A>(f);
 
391
 
//These are SGI extensions which are checked for by some conformance checks.  They
 
392
 
// are *NOT* part of the C++ standard, however
 
394
 
template <class Op1, class Op2> class _UCXXEXPORT unary_compose :
 
395
 
        public std::unary_function<typename Op2::argument_type,
 
396
 
                typename Op1::result_type>
 
402
 
        unary_compose(const Op1& x, const Op2& y) : mf1(x), mf2(y) {  }
 
403
 
        typename Op1::result_type operator()(const typename Op2::argument_type& x) const {
 
408
 
template <class Op1, class Op2> _UCXXEXPORT 
 
409
 
inline unary_compose<Op1, Op2>
 
410
 
compose1(const Op1& fn1, const Op2& fn2){
 
411
 
        return unary_compose<Op1, Op2>(fn1, fn2);
 
414
 
template <class Op1, class Op2, class Op3> class _UCXXEXPORT binary_compose : 
 
415
 
        public std::unary_function<typename Op2::argument_type, typename Op1::result_type>
 
422
 
        binary_compose(const Op1 & x, const Op2 & y, const Op3 & z)
 
423
 
                : mf1(x), mf2(y), mf3(z){  }
 
424
 
        typename Op1::result_type operator()(const typename Op2::argument_type & x) const {
 
425
 
                return mf1(mf2(x), mf3(x));
 
429
 
template <class Op1, class Op2, class Op3> inline _UCXXEXPORT binary_compose<Op1, Op2, Op3>
 
430
 
compose2(const Op1 & fn1, const Op2 & fn2, const Op3 & fn3){
 
431
 
        return binary_compose<Op1, Op2, Op3>(fn1, fn2, fn3);
 
434
 
#pragma GCC visibility pop