• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright (c) 1994
4  * Hewlett-Packard Company
5  *
6  * Copyright (c) 1996-1998
7  * Silicon Graphics Computer Systems, Inc.
8  *
9  * Copyright (c) 1997
10  * Moscow Center for SPARC Technology
11  *
12  * Copyright (c) 1999
13  * Boris Fomitchev
14  *
15  * This material is provided "as is", with absolutely no warranty expressed
16  * or implied. Any use is at your own risk.
17  *
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.
23  *
24  */
25 
26 /* NOTE: This is an internal header file, included by other STL headers.
27  *   You should not attempt to use it directly.
28  */
29 
30 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
31 #define _STLP_INTERNAL_FUNCTION_BASE_H
32 
33 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_TYPE_TRAITS_H)
34 #  include <stl/type_traits.h>
35 #endif
36 
37 _STLP_BEGIN_NAMESPACE
38 
39 template <class _Arg, class _Result>
40 struct unary_function {
41   typedef _Arg argument_type;
42   typedef _Result result_type;
43 #if !defined (__BORLANDC__) || (__BORLANDC__ < 0x580)
44 protected:
45   /* This class purpose is to be derived but it is not polymorphic so users should never try
46    * to destroy an instance of it directly. The protected non-virtual destructor make this
47    * fact obvious at compilation time. */
~unary_functionunary_function48   ~unary_function() {}
49 #endif
50 };
51 
52 template <class _Arg1, class _Arg2, class _Result>
53 struct binary_function {
54   typedef _Arg1 first_argument_type;
55   typedef _Arg2 second_argument_type;
56   typedef _Result result_type;
57 #if !defined (__BORLANDC__) || (__BORLANDC__ < 0x580)
58 protected:
59   /* See unary_function comment. */
~binary_functionbinary_function60   ~binary_function() {}
61 #endif
62 };
63 
64 template <class _Tp>
65 struct equal_to : public binary_function<_Tp, _Tp, bool> {
operatorequal_to66   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
67 };
68 
69 template <class _Tp>
70 struct less : public binary_function<_Tp,_Tp,bool>
71 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
72 /* less is the default template parameter for many STL containers, to fully use
73  * the move constructor feature we need to know that the default less is just a
74  * functor.
75  */
76               , public __stlport_class<less<_Tp> >
77 #endif
78 {
operatorless79   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
80 
81 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
_M_swap_workaroundless82   void _M_swap_workaround(less<_Tp>& __x) {}
83 #endif
84 };
85 
86 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
87 template <class _Tp>
88 struct __type_traits<less<_Tp> > {
89 #if !defined (__BORLANDC__)
90   typedef typename _IsSTLportClass<less<_Tp> >::_Ret _STLportLess;
91 #else
92   enum { _Is = _IsSTLportClass<less<_Tp> >::_Is };
93   typedef typename __bool2type<_Is>::_Ret _STLportLess;
94 #endif
95   typedef _STLportLess has_trivial_default_constructor;
96   typedef _STLportLess has_trivial_copy_constructor;
97   typedef _STLportLess has_trivial_assignment_operator;
98   typedef _STLportLess has_trivial_destructor;
99   typedef _STLportLess is_POD_type;
100 };
101 #endif
102 
103 _STLP_MOVE_TO_PRIV_NAMESPACE
104 
105 template <class _Tp>
106 less<_Tp> __less(_Tp* ) { return less<_Tp>(); }
107 
108 template <class _Tp>
109 equal_to<_Tp> __equal_to(_Tp* ) { return equal_to<_Tp>(); }
110 
111 _STLP_MOVE_TO_STD_NAMESPACE
112 
113 template <class _Tp>
114 struct plus : public binary_function<_Tp, _Tp, _Tp> {
115   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
116 };
117 
118 template <class _Tp>
119 struct minus : public binary_function<_Tp, _Tp, _Tp> {
120   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
121 };
122 
123 _STLP_MOVE_TO_PRIV_NAMESPACE
124 
125 template <class _Tp>
126 plus<_Tp> __plus(_Tp* ) { return plus<_Tp>(); }
127 
128 template <class _Tp>
129 minus<_Tp> __minus(_Tp* ) { return minus<_Tp>(); }
130 
131 _STLP_MOVE_TO_STD_NAMESPACE
132 
133 template <class _Tp>
134 struct multiplies : public binary_function<_Tp, _Tp, _Tp> {
135   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
136 };
137 
138 _STLP_MOVE_TO_PRIV_NAMESPACE
139 
140 template <class _Pair>
141 struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
142   const typename _Pair::first_type& operator()(const _Pair& __x) const {
143     return __x.first;
144   }
145 };
146 
147 template <class _Pair>
148 struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type> {
149   const typename _Pair::second_type& operator()(const _Pair& __x) const {
150     return __x.second;
151   }
152 };
153 
154 // project1st and project2nd are extensions: they are not part of the standard
155 template <class _Arg1, class _Arg2>
156 struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
157   _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
158 };
159 
160 template <class _Arg1, class _Arg2>
161 struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
162   _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
163 };
164 
165 #if defined (_STLP_MULTI_CONST_TEMPLATE_ARG_BUG)
166 // fbp : sort of select1st just for maps
167 template <class _Pair, class _Whatever>
168 // JDJ (CW Pro1 doesn't like const when first_type is also const)
169 struct __Select1st_hint : public unary_function<_Pair, _Whatever> {
170     const _Whatever& operator () (const _Pair& __x) const { return __x.first; }
171 };
172 #  define  _STLP_SELECT1ST(__x,__y) _STLP_PRIV __Select1st_hint< __x, __y >
173 #else
174 #  define  _STLP_SELECT1ST(__x, __y) _STLP_PRIV _Select1st< __x >
175 #endif
176 
177 template <class _Tp>
178 struct _Identity : public unary_function<_Tp,_Tp> {
179   const _Tp& operator()(const _Tp& __x) const { return __x; }
180 };
181 
182 template <class _Result, class _Argument>
183 struct _Constant_unary_fun {
184   typedef _Argument argument_type;
185   typedef  _Result  result_type;
186   result_type _M_val;
187 
188   _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
189   const result_type& operator()(const _Argument&) const { return _M_val; }
190 };
191 
192 template <class _Result, class _Arg1, class _Arg2>
193 struct _Constant_binary_fun {
194   typedef  _Arg1   first_argument_type;
195   typedef  _Arg2   second_argument_type;
196   typedef  _Result result_type;
197   _Result _M_val;
198 
199   _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
200   const result_type& operator()(const _Arg1&, const _Arg2&) const {
201     return _M_val;
202   }
203 };
204 
205 // identity_element (not part of the C++ standard).
206 template <class _Tp> inline _Tp __identity_element(plus<_Tp>) {  return _Tp(0); }
207 template <class _Tp> inline _Tp __identity_element(multiplies<_Tp>) { return _Tp(1); }
208 
209 _STLP_MOVE_TO_STD_NAMESPACE
210 
211 _STLP_END_NAMESPACE
212 
213 #endif /* _STLP_INTERNAL_FUNCTION_BASE_H */
214 
215 // Local Variables:
216 // mode:C++
217 // End:
218