williamr@4
|
1 |
/*
|
williamr@4
|
2 |
*
|
williamr@4
|
3 |
* Copyright (c) 1994
|
williamr@4
|
4 |
* Hewlett-Packard Company
|
williamr@4
|
5 |
*
|
williamr@4
|
6 |
* Copyright (c) 1996-1998
|
williamr@4
|
7 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* Copyright (c) 1997
|
williamr@4
|
10 |
* Moscow Center for SPARC Technology
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Copyright (c) 1999
|
williamr@4
|
13 |
* Boris Fomitchev
|
williamr@4
|
14 |
*
|
williamr@4
|
15 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
16 |
* or implied. Any use is at your own risk.
|
williamr@4
|
17 |
*
|
williamr@4
|
18 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
19 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
20 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
21 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
22 |
* modified is included with the above copyright notice.
|
williamr@4
|
23 |
*
|
williamr@4
|
24 |
*/
|
williamr@4
|
25 |
|
williamr@4
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@4
|
27 |
* You should not attempt to use it directly.
|
williamr@4
|
28 |
*/
|
williamr@4
|
29 |
|
williamr@4
|
30 |
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
|
williamr@4
|
31 |
#define _STLP_INTERNAL_FUNCTION_BASE_H
|
williamr@4
|
32 |
|
williamr@4
|
33 |
#ifndef _STLP_CONFIG_H
|
williamr@4
|
34 |
#include <stl/_config.h>
|
williamr@4
|
35 |
#endif
|
williamr@4
|
36 |
|
williamr@4
|
37 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
38 |
|
williamr@4
|
39 |
template <class _Arg, class _Result>
|
williamr@4
|
40 |
struct unary_function {
|
williamr@4
|
41 |
typedef _Arg argument_type;
|
williamr@4
|
42 |
typedef _Result result_type;
|
williamr@4
|
43 |
};
|
williamr@4
|
44 |
|
williamr@4
|
45 |
template <class _Arg1, class _Arg2, class _Result>
|
williamr@4
|
46 |
struct binary_function {
|
williamr@4
|
47 |
typedef _Arg1 first_argument_type;
|
williamr@4
|
48 |
typedef _Arg2 second_argument_type;
|
williamr@4
|
49 |
typedef _Result result_type;
|
williamr@4
|
50 |
};
|
williamr@4
|
51 |
|
williamr@4
|
52 |
template <class _Tp>
|
williamr@4
|
53 |
struct equal_to : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
54 |
{
|
williamr@4
|
55 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
|
williamr@4
|
56 |
};
|
williamr@4
|
57 |
|
williamr@4
|
58 |
template <class _Tp>
|
williamr@4
|
59 |
struct not_equal_to : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
60 |
{
|
williamr@4
|
61 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
|
williamr@4
|
62 |
};
|
williamr@4
|
63 |
|
williamr@4
|
64 |
template <class _Tp>
|
williamr@4
|
65 |
struct greater : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
66 |
{
|
williamr@4
|
67 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
|
williamr@4
|
68 |
};
|
williamr@4
|
69 |
|
williamr@4
|
70 |
template <class _Tp>
|
williamr@4
|
71 |
struct less : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
72 |
{
|
williamr@4
|
73 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
|
williamr@4
|
74 |
};
|
williamr@4
|
75 |
|
williamr@4
|
76 |
template <class _Tp>
|
williamr@4
|
77 |
struct greater_equal : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
78 |
{
|
williamr@4
|
79 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
|
williamr@4
|
80 |
};
|
williamr@4
|
81 |
|
williamr@4
|
82 |
template <class _Tp>
|
williamr@4
|
83 |
struct less_equal : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
84 |
{
|
williamr@4
|
85 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
|
williamr@4
|
86 |
};
|
williamr@4
|
87 |
|
williamr@4
|
88 |
template <class _Tp>
|
williamr@4
|
89 |
less<_Tp> __less(_Tp* ) { return less<_Tp>(); }
|
williamr@4
|
90 |
|
williamr@4
|
91 |
template <class _Tp>
|
williamr@4
|
92 |
equal_to<_Tp> __equal_to(_Tp* ) { return equal_to<_Tp>(); }
|
williamr@4
|
93 |
|
williamr@4
|
94 |
template <class _Tp>
|
williamr@4
|
95 |
struct plus : public binary_function<_Tp,_Tp,_Tp> {
|
williamr@4
|
96 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
|
williamr@4
|
97 |
};
|
williamr@4
|
98 |
|
williamr@4
|
99 |
template <class _Tp>
|
williamr@4
|
100 |
struct minus : public binary_function<_Tp,_Tp,_Tp> {
|
williamr@4
|
101 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
|
williamr@4
|
102 |
};
|
williamr@4
|
103 |
|
williamr@4
|
104 |
template <class _Tp>
|
williamr@4
|
105 |
plus<_Tp> __plus(_Tp* ) { return plus<_Tp>(); }
|
williamr@4
|
106 |
|
williamr@4
|
107 |
template <class _Tp>
|
williamr@4
|
108 |
minus<_Tp> __minus(_Tp* ) { return minus<_Tp>(); }
|
williamr@4
|
109 |
|
williamr@4
|
110 |
template <class _Tp>
|
williamr@4
|
111 |
struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
|
williamr@4
|
112 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
|
williamr@4
|
113 |
};
|
williamr@4
|
114 |
|
williamr@4
|
115 |
template <class _Tp>
|
williamr@4
|
116 |
struct divides : public binary_function<_Tp,_Tp,_Tp> {
|
williamr@4
|
117 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
|
williamr@4
|
118 |
};
|
williamr@4
|
119 |
|
williamr@4
|
120 |
template <class _Tp>
|
williamr@4
|
121 |
struct modulus : public binary_function<_Tp,_Tp,_Tp>
|
williamr@4
|
122 |
{
|
williamr@4
|
123 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
|
williamr@4
|
124 |
};
|
williamr@4
|
125 |
|
williamr@4
|
126 |
template <class _Tp>
|
williamr@4
|
127 |
struct negate : public unary_function<_Tp,_Tp>
|
williamr@4
|
128 |
{
|
williamr@4
|
129 |
_Tp operator()(const _Tp& __x) const { return -__x; }
|
williamr@4
|
130 |
};
|
williamr@4
|
131 |
|
williamr@4
|
132 |
template <class _Tp>
|
williamr@4
|
133 |
struct logical_and : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
134 |
{
|
williamr@4
|
135 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
|
williamr@4
|
136 |
};
|
williamr@4
|
137 |
|
williamr@4
|
138 |
template <class _Tp>
|
williamr@4
|
139 |
struct logical_or : public binary_function<_Tp,_Tp,bool>
|
williamr@4
|
140 |
{
|
williamr@4
|
141 |
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
|
williamr@4
|
142 |
};
|
williamr@4
|
143 |
|
williamr@4
|
144 |
template <class _Tp>
|
williamr@4
|
145 |
struct logical_not : public unary_function<_Tp,bool>
|
williamr@4
|
146 |
{
|
williamr@4
|
147 |
bool operator()(const _Tp& __x) const { return !__x; }
|
williamr@4
|
148 |
};
|
williamr@4
|
149 |
|
williamr@4
|
150 |
template <class _Pair>
|
williamr@4
|
151 |
struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
|
williamr@4
|
152 |
const typename _Pair::first_type& operator()(const _Pair& __x) const {
|
williamr@4
|
153 |
return __x.first;
|
williamr@4
|
154 |
}
|
williamr@4
|
155 |
};
|
williamr@4
|
156 |
|
williamr@4
|
157 |
template <class _Pair>
|
williamr@4
|
158 |
struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
|
williamr@4
|
159 |
{
|
williamr@4
|
160 |
const typename _Pair::second_type& operator()(const _Pair& __x) const {
|
williamr@4
|
161 |
return __x.second;
|
williamr@4
|
162 |
}
|
williamr@4
|
163 |
};
|
williamr@4
|
164 |
|
williamr@4
|
165 |
// project1st and project2nd are extensions: they are not part of the standard
|
williamr@4
|
166 |
template <class _Arg1, class _Arg2>
|
williamr@4
|
167 |
struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
|
williamr@4
|
168 |
_Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
|
williamr@4
|
169 |
};
|
williamr@4
|
170 |
|
williamr@4
|
171 |
template <class _Arg1, class _Arg2>
|
williamr@4
|
172 |
struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
|
williamr@4
|
173 |
_Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
|
williamr@4
|
174 |
};
|
williamr@4
|
175 |
|
williamr@4
|
176 |
#ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
|
williamr@4
|
177 |
// fbp : sort of select1st just for maps
|
williamr@4
|
178 |
template <class _Pair, class _Whatever>
|
williamr@4
|
179 |
// JDJ (CW Pro1 doesn't like const when first_type is also const)
|
williamr@4
|
180 |
struct __Select1st_hint : public unary_function<_Pair, _Whatever> {
|
williamr@4
|
181 |
const _Whatever& operator () (const _Pair& __x) const { return __x.first; }
|
williamr@4
|
182 |
};
|
williamr@4
|
183 |
# define _STLP_SELECT1ST(__x,__y) __Select1st_hint< __x, __y >
|
williamr@4
|
184 |
# else
|
williamr@4
|
185 |
# define _STLP_SELECT1ST(__x, __y) _Select1st< __x >
|
williamr@4
|
186 |
# endif
|
williamr@4
|
187 |
|
williamr@4
|
188 |
template <class _Tp>
|
williamr@4
|
189 |
struct _Identity : public unary_function<_Tp,_Tp> {
|
williamr@4
|
190 |
const _Tp& operator()(const _Tp& __x) const { return __x; }
|
williamr@4
|
191 |
};
|
williamr@4
|
192 |
|
williamr@4
|
193 |
template <class _Result, class _Argument>
|
williamr@4
|
194 |
struct _Constant_unary_fun {
|
williamr@4
|
195 |
typedef _Argument argument_type;
|
williamr@4
|
196 |
typedef _Result result_type;
|
williamr@4
|
197 |
result_type _M_val;
|
williamr@4
|
198 |
|
williamr@4
|
199 |
_Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
|
williamr@4
|
200 |
const result_type& operator()(const _Argument&) const { return _M_val; }
|
williamr@4
|
201 |
};
|
williamr@4
|
202 |
|
williamr@4
|
203 |
template <class _Result, class _Arg1, class _Arg2>
|
williamr@4
|
204 |
struct _Constant_binary_fun {
|
williamr@4
|
205 |
typedef _Arg1 first_argument_type;
|
williamr@4
|
206 |
typedef _Arg2 second_argument_type;
|
williamr@4
|
207 |
typedef _Result result_type;
|
williamr@4
|
208 |
_Result _M_val;
|
williamr@4
|
209 |
|
williamr@4
|
210 |
_Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
|
williamr@4
|
211 |
const result_type& operator()(const _Arg1&, const _Arg2&) const {
|
williamr@4
|
212 |
return _M_val;
|
williamr@4
|
213 |
}
|
williamr@4
|
214 |
};
|
williamr@4
|
215 |
|
williamr@4
|
216 |
// identity_element (not part of the C++ standard).
|
williamr@4
|
217 |
template <class _Tp> inline _Tp __identity_element(plus<_Tp>) { return _Tp(0); }
|
williamr@4
|
218 |
template <class _Tp> inline _Tp __identity_element(multiplies<_Tp>) { return _Tp(1); }
|
williamr@4
|
219 |
|
williamr@4
|
220 |
_STLP_END_NAMESPACE
|
williamr@4
|
221 |
|
williamr@4
|
222 |
#endif /* _STLP_INTERNAL_FUNCTION_BASE_H */
|
williamr@4
|
223 |
|
williamr@4
|
224 |
// Local Variables:
|
williamr@4
|
225 |
// mode:C++
|
williamr@4
|
226 |
// End:
|