Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
4 * Hewlett-Packard Company
6 * Copyright (c) 1996-1998
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_FUNCTION_H
31 #define _STLP_INTERNAL_FUNCTION_H
33 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
34 #include <stl/_function_base.h>
39 # ifndef _STLP_NO_EXTENSIONS
40 // identity_element (not part of the C++ standard).
41 template <class _Tp> inline _Tp identity_element(plus<_Tp>) { return _Tp(0); }
42 template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) { return _Tp(1); }
45 # if defined (_STLP_BASE_TYPEDEF_BUG)
46 // this workaround is needed for SunPro 4.0.1
47 // suggested by "Martin Abernethy" <gma@paston.co.uk>:
49 // We have to introduce the XXary_predicate_aux structures in order to
50 // access the argument and return types of predicate functions supplied
51 // as type parameters. SUN C++ 4.0.1 compiler gives errors for template type parameters
52 // of the form 'name1::name2', where name1 is itself a type parameter.
53 template <class _Pair>
54 struct __pair_aux : private _Pair
56 typedef typename _Pair::first_type first_type;
57 typedef typename _Pair::second_type second_type;
60 template <class _Operation>
61 struct __unary_fun_aux : private _Operation
63 typedef typename _Operation::argument_type argument_type;
64 typedef typename _Operation::result_type result_type;
67 template <class _Operation>
68 struct __binary_fun_aux : private _Operation
70 typedef typename _Operation::first_argument_type first_argument_type;
71 typedef typename _Operation::second_argument_type second_argument_type;
72 typedef typename _Operation::result_type result_type;
75 # define __UNARY_ARG(__Operation,__type) __unary_fun_aux<__Operation>::__type
76 # define __BINARY_ARG(__Operation,__type) __binary_fun_aux<__Operation>::__type
77 # define __PAIR_ARG(__Pair,__type) __pair_aux<__Pair>::__type
79 # define __UNARY_ARG(__Operation,__type) __Operation::__type
80 # define __BINARY_ARG(__Operation,__type) __Operation::__type
81 # define __PAIR_ARG(__Pair,__type) __Pair::__type
84 template <class _Predicate>
86 public unary_function<typename __UNARY_ARG(_Predicate,argument_type), bool> {
90 explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
91 bool operator()(const typename _Predicate::argument_type& __x) const {
96 template <class _Predicate>
97 inline unary_negate<_Predicate>
98 not1(const _Predicate& __pred)
100 return unary_negate<_Predicate>(__pred);
103 template <class _Predicate>
105 : public binary_function<typename __BINARY_ARG(_Predicate,first_argument_type),
106 typename __BINARY_ARG(_Predicate,second_argument_type),
111 explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
112 bool operator()(const typename _Predicate::first_argument_type& __x,
113 const typename _Predicate::second_argument_type& __y) const
115 return !_M_pred(__x, __y);
119 template <class _Predicate>
120 inline binary_negate<_Predicate>
121 not2(const _Predicate& __pred)
123 return binary_negate<_Predicate>(__pred);
126 template <class _Operation>
128 public unary_function<typename __BINARY_ARG(_Operation,second_argument_type),
129 typename __BINARY_ARG(_Operation,result_type) > {
132 typename _Operation::first_argument_type value;
134 binder1st(const _Operation& __x,
135 const typename _Operation::first_argument_type& __y)
136 : op(__x), value(__y) {}
138 typename _Operation::result_type
139 operator()(const typename _Operation::second_argument_type& __x) const {
140 return op(value, __x);
143 typename _Operation::result_type
144 operator()(typename _Operation::second_argument_type& __x) const {
145 return op(value, __x);
149 template <class _Operation, class _Tp>
150 inline binder1st<_Operation>
151 bind1st(const _Operation& __fn, const _Tp& __x)
153 typedef typename _Operation::first_argument_type _Arg1_type;
154 return binder1st<_Operation>(__fn, _Arg1_type(__x));
157 template <class _Operation>
159 : public unary_function<typename __BINARY_ARG(_Operation,first_argument_type),
160 typename __BINARY_ARG(_Operation,result_type)> {
163 typename _Operation::second_argument_type value;
165 binder2nd(const _Operation& __x,
166 const typename _Operation::second_argument_type& __y)
167 : op(__x), value(__y) {}
169 typename _Operation::result_type
170 operator()(const typename _Operation::first_argument_type& __x) const {
171 return op(__x, value);
174 typename _Operation::result_type
175 operator()(typename _Operation::first_argument_type& __x) const {
176 return op(__x, value);
180 template <class _Operation, class _Tp>
181 inline binder2nd<_Operation>
182 bind2nd(const _Operation& __fn, const _Tp& __x)
184 typedef typename _Operation::second_argument_type _Arg2_type;
185 return binder2nd<_Operation>(__fn, _Arg2_type(__x));
188 # ifndef _STLP_NO_EXTENSIONS
189 // unary_compose and binary_compose (extensions, not part of the standard).
191 template <class _Operation1, class _Operation2>
192 class unary_compose :
193 public unary_function<typename __UNARY_ARG(_Operation2,argument_type),
194 typename __UNARY_ARG(_Operation1,result_type)> {
199 unary_compose(const _Operation1& __x, const _Operation2& __y)
200 : _M_fn1(__x), _M_fn2(__y) {}
202 typename _Operation1::result_type
203 operator()(const typename _Operation2::argument_type& __x) const {
204 return _M_fn1(_M_fn2(__x));
207 typename _Operation1::result_type
208 operator()(typename _Operation2::argument_type& __x) const {
209 return _M_fn1(_M_fn2(__x));
213 template <class _Operation1, class _Operation2>
214 inline unary_compose<_Operation1,_Operation2>
215 compose1(const _Operation1& __fn1, const _Operation2& __fn2)
217 return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
220 template <class _Operation1, class _Operation2, class _Operation3>
221 class binary_compose :
222 public unary_function<typename __UNARY_ARG(_Operation2,argument_type),
223 typename __BINARY_ARG(_Operation1,result_type)> {
229 binary_compose(const _Operation1& __x, const _Operation2& __y,
230 const _Operation3& __z)
231 : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
233 typename _Operation1::result_type
234 operator()(const typename _Operation2::argument_type& __x) const {
235 return _M_fn1(_M_fn2(__x), _M_fn3(__x));
238 typename _Operation1::result_type
239 operator()(typename _Operation2::argument_type& __x) const {
240 return _M_fn1(_M_fn2(__x), _M_fn3(__x));
244 template <class _Operation1, class _Operation2, class _Operation3>
245 inline binary_compose<_Operation1, _Operation2, _Operation3>
246 compose2(const _Operation1& __fn1, const _Operation2& __fn2,
247 const _Operation3& __fn3)
249 return binary_compose<_Operation1,_Operation2,_Operation3>
250 (__fn1, __fn2, __fn3);
253 # endif /* _STLP_NO_EXTENSIONS */
255 # ifndef _STLP_NO_EXTENSIONS
257 // identity is an extension: it is not part of the standard.
258 template <class _Tp> struct identity : public _Identity<_Tp> {};
259 // select1st and select2nd are extensions: they are not part of the standard.
260 template <class _Pair> struct select1st : public _Select1st<_Pair> {};
261 template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};
263 template <class _Arg1, class _Arg2>
264 struct project1st : public _Project1st<_Arg1, _Arg2> {};
266 template <class _Arg1, class _Arg2>
267 struct project2nd : public _Project2nd<_Arg1, _Arg2> {};
270 // constant_void_fun, constant_unary_fun, and constant_binary_fun are
271 // extensions: they are not part of the standard. (The same, of course,
272 // is true of the helper functions constant0, constant1, and constant2.)
274 template <class _Result>
275 struct _Constant_void_fun {
276 typedef _Result result_type;
279 _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
280 const result_type& operator()() const { return _M_val; }
284 template <class _Result>
285 struct constant_void_fun : public _Constant_void_fun<_Result> {
286 constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {}
289 template <class _Result, __DFL_TMPL_PARAM( _Argument , _Result) >
290 struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
292 constant_unary_fun(const _Result& __v)
293 : _Constant_unary_fun<_Result, _Argument>(__v) {}
296 template <class _Result, __DFL_TMPL_PARAM( _Arg1 , _Result), __DFL_TMPL_PARAM( _Arg2 , _Arg1) >
297 struct constant_binary_fun
298 : public _Constant_binary_fun<_Result, _Arg1, _Arg2>
300 constant_binary_fun(const _Result& __v)
301 : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
304 template <class _Result>
305 inline constant_void_fun<_Result> constant0(const _Result& __val)
307 return constant_void_fun<_Result>(__val);
310 template <class _Result>
311 inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val)
313 return constant_unary_fun<_Result,_Result>(__val);
316 template <class _Result>
317 inline constant_binary_fun<_Result,_Result,_Result>
318 constant2(const _Result& __val)
320 return constant_binary_fun<_Result,_Result,_Result>(__val);
323 // subtractive_rng is an extension: it is not part of the standard.
324 // Note: this code assumes that int is 32 bits.
325 class subtractive_rng : public unary_function<_STLP_UINT32_T, _STLP_UINT32_T> {
327 _STLP_UINT32_T _M_table[55];
328 _STLP_UINT32_T _M_index1;
329 _STLP_UINT32_T _M_index2;
331 _STLP_UINT32_T operator()(_STLP_UINT32_T __limit) {
332 _M_index1 = (_M_index1 + 1) % 55;
333 _M_index2 = (_M_index2 + 1) % 55;
334 _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];
335 return _M_table[_M_index1] % __limit;
338 void _M_initialize(_STLP_UINT32_T __seed)
340 _STLP_UINT32_T __k = 1;
341 _M_table[54] = __seed;
343 for (__i = 0; __i < 54; __i++) {
344 _STLP_UINT32_T __ii = (21 * (__i + 1) % 55) - 1;
345 _M_table[__ii] = __k;
347 __seed = _M_table[__ii];
349 for (int __loop = 0; __loop < 4; __loop++) {
350 for (__i = 0; __i < 55; __i++)
351 _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
357 subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
358 subtractive_rng() { _M_initialize(161803398ul); }
361 # endif /* _STLP_NO_EXTENSIONS */
365 #include <stl/_function_adaptors.h>
367 #endif /* _STLP_INTERNAL_FUNCTION_H */