ReactOS 0.4.15-dev-7934-g1dc8d80
_function_base.h
Go to the documentation of this file.
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
38
39template <class _Arg, class _Result>
41 typedef _Arg argument_type;
42 typedef _Result result_type;
43#if !defined (__BORLANDC__) || (__BORLANDC__ < 0x580)
44protected:
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. */
49#endif
50};
51
52template <class _Arg1, class _Arg2, class _Result>
54 typedef _Arg1 first_argument_type;
55 typedef _Arg2 second_argument_type;
56 typedef _Result result_type;
57#if !defined (__BORLANDC__) || (__BORLANDC__ < 0x580)
58protected:
59 /* See unary_function comment. */
61#endif
62};
63
64template <class _Tp>
65struct equal_to : public binary_function<_Tp, _Tp, bool> {
66 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
67};
68
69template <class _Tp>
70struct 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{
79 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)
82 void _M_swap_workaround(less<_Tp>& __x) {}
83#endif
84};
85
86#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
87template <class _Tp>
88struct __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
104
105template <class _Tp>
106less<_Tp> __less(_Tp* ) { return less<_Tp>(); }
107
108template <class _Tp>
110
112
113template <class _Tp>
114struct plus : public binary_function<_Tp, _Tp, _Tp> {
115 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
116};
117
118template <class _Tp>
119struct minus : public binary_function<_Tp, _Tp, _Tp> {
120 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
121};
122
124
125template <class _Tp>
126plus<_Tp> __plus(_Tp* ) { return plus<_Tp>(); }
127
128template <class _Tp>
129minus<_Tp> __minus(_Tp* ) { return minus<_Tp>(); }
130
132
133template <class _Tp>
134struct multiplies : public binary_function<_Tp, _Tp, _Tp> {
135 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
136};
137
139
140template <class _Pair>
141struct _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
147template <class _Pair>
148struct _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
155template <class _Arg1, class _Arg2>
156struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
157 _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
158};
159
160template <class _Arg1, class _Arg2>
161struct _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
167template <class _Pair, class _Whatever>
168// JDJ (CW Pro1 doesn't like const when first_type is also const)
169struct __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
177template <class _Tp>
178struct _Identity : public unary_function<_Tp,_Tp> {
179 const _Tp& operator()(const _Tp& __x) const { return __x; }
180};
181
182template <class _Result, class _Argument>
184 typedef _Argument argument_type;
185 typedef _Result result_type;
187
189 const result_type& operator()(const _Argument&) const { return _M_val; }
190};
191
192template <class _Result, class _Arg1, class _Arg2>
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).
206template <class _Tp> inline _Tp __identity_element(plus<_Tp>) { return _Tp(0); }
207template <class _Tp> inline _Tp __identity_element(multiplies<_Tp>) { return _Tp(1); }
208
210
212
213#endif /* _STLP_INTERNAL_FUNCTION_BASE_H */
214
215// Local Variables:
216// mode:C++
217// End:
_STLP_MOVE_TO_PRIV_NAMESPACE plus< _Tp > __plus(_Tp *)
_Tp __identity_element(plus< _Tp >)
minus< _Tp > __minus(_Tp *)
_STLP_MOVE_TO_PRIV_NAMESPACE less< _Tp > __less(_Tp *)
equal_to< _Tp > __equal_to(_Tp *)
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
_Constant_binary_fun(const _Result &__v)
const result_type & operator()(const _Arg1 &, const _Arg2 &) const
const result_type & operator()(const _Argument &) const
_Constant_unary_fun(const result_type &__v)
const _Tp & operator()(const _Tp &__x) const
_Arg1 operator()(const _Arg1 &__x, const _Arg2 &) const
_Arg2 operator()(const _Arg1 &, const _Arg2 &__y) const
const _Pair::first_type & operator()(const _Pair &__x) const
const _Pair::second_type & operator()(const _Pair &__x) const
__bool2type< pod >::_Ret is_POD_type
__bool2type< trivial_destructor >::_Ret has_trivial_destructor
__bool2type< trivial_constructor >::_Ret has_trivial_default_constructor
__bool2type< trivial_copy >::_Ret has_trivial_copy_constructor
__bool2type< trivial_assign >::_Ret has_trivial_assignment_operator
_Arg1 first_argument_type
_Arg2 second_argument_type
bool operator()(const _Tp &__x, const _Tp &__y) const
bool operator()(const _Tp &__x, const _Tp &__y) const
_Tp operator()(const _Tp &__x, const _Tp &__y) const
_Tp operator()(const _Tp &__x, const _Tp &__y) const
_Tp operator()(const _Tp &__x, const _Tp &__y) const
_Result result_type