libstdc++
|
00001 // Functor implementations -*- C++ -*- 00002 00003 // Copyright (C) 2001-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /* 00026 * 00027 * Copyright (c) 1994 00028 * Hewlett-Packard Company 00029 * 00030 * Permission to use, copy, modify, distribute and sell this software 00031 * and its documentation for any purpose is hereby granted without fee, 00032 * provided that the above copyright notice appear in all copies and 00033 * that both that copyright notice and this permission notice appear 00034 * in supporting documentation. Hewlett-Packard Company makes no 00035 * representations about the suitability of this software for any 00036 * purpose. It is provided "as is" without express or implied warranty. 00037 * 00038 * 00039 * Copyright (c) 1996-1998 00040 * Silicon Graphics Computer Systems, Inc. 00041 * 00042 * Permission to use, copy, modify, distribute and sell this software 00043 * and its documentation for any purpose is hereby granted without fee, 00044 * provided that the above copyright notice appear in all copies and 00045 * that both that copyright notice and this permission notice appear 00046 * in supporting documentation. Silicon Graphics makes no 00047 * representations about the suitability of this software for any 00048 * purpose. It is provided "as is" without express or implied warranty. 00049 */ 00050 00051 /** @file bits/stl_function.h 00052 * This is an internal header file, included by other library headers. 00053 * Do not attempt to use it directly. @headername{functional} 00054 */ 00055 00056 #ifndef _STL_FUNCTION_H 00057 #define _STL_FUNCTION_H 1 00058 00059 #if __cplusplus > 201103L 00060 #include <bits/move.h> 00061 #endif 00062 00063 namespace std _GLIBCXX_VISIBILITY(default) 00064 { 00065 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00066 00067 // 20.3.1 base classes 00068 /** @defgroup functors Function Objects 00069 * @ingroup utilities 00070 * 00071 * Function objects, or @e functors, are objects with an @c operator() 00072 * defined and accessible. They can be passed as arguments to algorithm 00073 * templates and used in place of a function pointer. Not only is the 00074 * resulting expressiveness of the library increased, but the generated 00075 * code can be more efficient than what you might write by hand. When we 00076 * refer to @a functors, then, generally we include function pointers in 00077 * the description as well. 00078 * 00079 * Often, functors are only created as temporaries passed to algorithm 00080 * calls, rather than being created as named variables. 00081 * 00082 * Two examples taken from the standard itself follow. To perform a 00083 * by-element addition of two vectors @c a and @c b containing @c double, 00084 * and put the result in @c a, use 00085 * \code 00086 * transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>()); 00087 * \endcode 00088 * To negate every element in @c a, use 00089 * \code 00090 * transform(a.begin(), a.end(), a.begin(), negate<double>()); 00091 * \endcode 00092 * The addition and negation functions will be inlined directly. 00093 * 00094 * The standard functors are derived from structs named @c unary_function 00095 * and @c binary_function. These two classes contain nothing but typedefs, 00096 * to aid in generic (template) programming. If you write your own 00097 * functors, you might consider doing the same. 00098 * 00099 * @{ 00100 */ 00101 /** 00102 * This is one of the @link functors functor base classes@endlink. 00103 */ 00104 template<typename _Arg, typename _Result> 00105 struct unary_function 00106 { 00107 /// @c argument_type is the type of the argument 00108 typedef _Arg argument_type; 00109 00110 /// @c result_type is the return type 00111 typedef _Result result_type; 00112 }; 00113 00114 /** 00115 * This is one of the @link functors functor base classes@endlink. 00116 */ 00117 template<typename _Arg1, typename _Arg2, typename _Result> 00118 struct binary_function 00119 { 00120 /// @c first_argument_type is the type of the first argument 00121 typedef _Arg1 first_argument_type; 00122 00123 /// @c second_argument_type is the type of the second argument 00124 typedef _Arg2 second_argument_type; 00125 00126 /// @c result_type is the return type 00127 typedef _Result result_type; 00128 }; 00129 /** @} */ 00130 00131 // 20.3.2 arithmetic 00132 /** @defgroup arithmetic_functors Arithmetic Classes 00133 * @ingroup functors 00134 * 00135 * Because basic math often needs to be done during an algorithm, 00136 * the library provides functors for those operations. See the 00137 * documentation for @link functors the base classes@endlink 00138 * for examples of their use. 00139 * 00140 * @{ 00141 */ 00142 00143 #if __cplusplus > 201103L 00144 struct __is_transparent; // undefined 00145 00146 template<typename _Tp = void> 00147 struct plus; 00148 00149 template<typename _Tp = void> 00150 struct minus; 00151 00152 template<typename _Tp = void> 00153 struct multiplies; 00154 00155 template<typename _Tp = void> 00156 struct divides; 00157 00158 template<typename _Tp = void> 00159 struct modulus; 00160 00161 template<typename _Tp = void> 00162 struct negate; 00163 #endif 00164 00165 /// One of the @link arithmetic_functors math functors@endlink. 00166 template<typename _Tp> 00167 struct plus : public binary_function<_Tp, _Tp, _Tp> 00168 { 00169 _GLIBCXX14_CONSTEXPR 00170 _Tp 00171 operator()(const _Tp& __x, const _Tp& __y) const 00172 { return __x + __y; } 00173 }; 00174 00175 /// One of the @link arithmetic_functors math functors@endlink. 00176 template<typename _Tp> 00177 struct minus : public binary_function<_Tp, _Tp, _Tp> 00178 { 00179 _GLIBCXX14_CONSTEXPR 00180 _Tp 00181 operator()(const _Tp& __x, const _Tp& __y) const 00182 { return __x - __y; } 00183 }; 00184 00185 /// One of the @link arithmetic_functors math functors@endlink. 00186 template<typename _Tp> 00187 struct multiplies : public binary_function<_Tp, _Tp, _Tp> 00188 { 00189 _GLIBCXX14_CONSTEXPR 00190 _Tp 00191 operator()(const _Tp& __x, const _Tp& __y) const 00192 { return __x * __y; } 00193 }; 00194 00195 /// One of the @link arithmetic_functors math functors@endlink. 00196 template<typename _Tp> 00197 struct divides : public binary_function<_Tp, _Tp, _Tp> 00198 { 00199 _GLIBCXX14_CONSTEXPR 00200 _Tp 00201 operator()(const _Tp& __x, const _Tp& __y) const 00202 { return __x / __y; } 00203 }; 00204 00205 /// One of the @link arithmetic_functors math functors@endlink. 00206 template<typename _Tp> 00207 struct modulus : public binary_function<_Tp, _Tp, _Tp> 00208 { 00209 _GLIBCXX14_CONSTEXPR 00210 _Tp 00211 operator()(const _Tp& __x, const _Tp& __y) const 00212 { return __x % __y; } 00213 }; 00214 00215 /// One of the @link arithmetic_functors math functors@endlink. 00216 template<typename _Tp> 00217 struct negate : public unary_function<_Tp, _Tp> 00218 { 00219 _GLIBCXX14_CONSTEXPR 00220 _Tp 00221 operator()(const _Tp& __x) const 00222 { return -__x; } 00223 }; 00224 00225 #if __cplusplus > 201103L 00226 00227 #define __cpp_lib_transparent_operators 201510 00228 00229 template<> 00230 struct plus<void> 00231 { 00232 template <typename _Tp, typename _Up> 00233 _GLIBCXX14_CONSTEXPR 00234 auto 00235 operator()(_Tp&& __t, _Up&& __u) const 00236 noexcept(noexcept(std::forward<_Tp>(__t) + std::forward<_Up>(__u))) 00237 -> decltype(std::forward<_Tp>(__t) + std::forward<_Up>(__u)) 00238 { return std::forward<_Tp>(__t) + std::forward<_Up>(__u); } 00239 00240 typedef __is_transparent is_transparent; 00241 }; 00242 00243 /// One of the @link arithmetic_functors math functors@endlink. 00244 template<> 00245 struct minus<void> 00246 { 00247 template <typename _Tp, typename _Up> 00248 _GLIBCXX14_CONSTEXPR 00249 auto 00250 operator()(_Tp&& __t, _Up&& __u) const 00251 noexcept(noexcept(std::forward<_Tp>(__t) - std::forward<_Up>(__u))) 00252 -> decltype(std::forward<_Tp>(__t) - std::forward<_Up>(__u)) 00253 { return std::forward<_Tp>(__t) - std::forward<_Up>(__u); } 00254 00255 typedef __is_transparent is_transparent; 00256 }; 00257 00258 /// One of the @link arithmetic_functors math functors@endlink. 00259 template<> 00260 struct multiplies<void> 00261 { 00262 template <typename _Tp, typename _Up> 00263 _GLIBCXX14_CONSTEXPR 00264 auto 00265 operator()(_Tp&& __t, _Up&& __u) const 00266 noexcept(noexcept(std::forward<_Tp>(__t) * std::forward<_Up>(__u))) 00267 -> decltype(std::forward<_Tp>(__t) * std::forward<_Up>(__u)) 00268 { return std::forward<_Tp>(__t) * std::forward<_Up>(__u); } 00269 00270 typedef __is_transparent is_transparent; 00271 }; 00272 00273 /// One of the @link arithmetic_functors math functors@endlink. 00274 template<> 00275 struct divides<void> 00276 { 00277 template <typename _Tp, typename _Up> 00278 _GLIBCXX14_CONSTEXPR 00279 auto 00280 operator()(_Tp&& __t, _Up&& __u) const 00281 noexcept(noexcept(std::forward<_Tp>(__t) / std::forward<_Up>(__u))) 00282 -> decltype(std::forward<_Tp>(__t) / std::forward<_Up>(__u)) 00283 { return std::forward<_Tp>(__t) / std::forward<_Up>(__u); } 00284 00285 typedef __is_transparent is_transparent; 00286 }; 00287 00288 /// One of the @link arithmetic_functors math functors@endlink. 00289 template<> 00290 struct modulus<void> 00291 { 00292 template <typename _Tp, typename _Up> 00293 _GLIBCXX14_CONSTEXPR 00294 auto 00295 operator()(_Tp&& __t, _Up&& __u) const 00296 noexcept(noexcept(std::forward<_Tp>(__t) % std::forward<_Up>(__u))) 00297 -> decltype(std::forward<_Tp>(__t) % std::forward<_Up>(__u)) 00298 { return std::forward<_Tp>(__t) % std::forward<_Up>(__u); } 00299 00300 typedef __is_transparent is_transparent; 00301 }; 00302 00303 /// One of the @link arithmetic_functors math functors@endlink. 00304 template<> 00305 struct negate<void> 00306 { 00307 template <typename _Tp> 00308 _GLIBCXX14_CONSTEXPR 00309 auto 00310 operator()(_Tp&& __t) const 00311 noexcept(noexcept(-std::forward<_Tp>(__t))) 00312 -> decltype(-std::forward<_Tp>(__t)) 00313 { return -std::forward<_Tp>(__t); } 00314 00315 typedef __is_transparent is_transparent; 00316 }; 00317 #endif 00318 /** @} */ 00319 00320 // 20.3.3 comparisons 00321 /** @defgroup comparison_functors Comparison Classes 00322 * @ingroup functors 00323 * 00324 * The library provides six wrapper functors for all the basic comparisons 00325 * in C++, like @c <. 00326 * 00327 * @{ 00328 */ 00329 #if __cplusplus > 201103L 00330 template<typename _Tp = void> 00331 struct equal_to; 00332 00333 template<typename _Tp = void> 00334 struct not_equal_to; 00335 00336 template<typename _Tp = void> 00337 struct greater; 00338 00339 template<typename _Tp = void> 00340 struct less; 00341 00342 template<typename _Tp = void> 00343 struct greater_equal; 00344 00345 template<typename _Tp = void> 00346 struct less_equal; 00347 #endif 00348 00349 /// One of the @link comparison_functors comparison functors@endlink. 00350 template<typename _Tp> 00351 struct equal_to : public binary_function<_Tp, _Tp, bool> 00352 { 00353 _GLIBCXX14_CONSTEXPR 00354 bool 00355 operator()(const _Tp& __x, const _Tp& __y) const 00356 { return __x == __y; } 00357 }; 00358 00359 /// One of the @link comparison_functors comparison functors@endlink. 00360 template<typename _Tp> 00361 struct not_equal_to : public binary_function<_Tp, _Tp, bool> 00362 { 00363 _GLIBCXX14_CONSTEXPR 00364 bool 00365 operator()(const _Tp& __x, const _Tp& __y) const 00366 { return __x != __y; } 00367 }; 00368 00369 /// One of the @link comparison_functors comparison functors@endlink. 00370 template<typename _Tp> 00371 struct greater : public binary_function<_Tp, _Tp, bool> 00372 { 00373 _GLIBCXX14_CONSTEXPR 00374 bool 00375 operator()(const _Tp& __x, const _Tp& __y) const 00376 { return __x > __y; } 00377 }; 00378 00379 /// One of the @link comparison_functors comparison functors@endlink. 00380 template<typename _Tp> 00381 struct less : public binary_function<_Tp, _Tp, bool> 00382 { 00383 _GLIBCXX14_CONSTEXPR 00384 bool 00385 operator()(const _Tp& __x, const _Tp& __y) const 00386 { return __x < __y; } 00387 }; 00388 00389 /// One of the @link comparison_functors comparison functors@endlink. 00390 template<typename _Tp> 00391 struct greater_equal : public binary_function<_Tp, _Tp, bool> 00392 { 00393 _GLIBCXX14_CONSTEXPR 00394 bool 00395 operator()(const _Tp& __x, const _Tp& __y) const 00396 { return __x >= __y; } 00397 }; 00398 00399 /// One of the @link comparison_functors comparison functors@endlink. 00400 template<typename _Tp> 00401 struct less_equal : public binary_function<_Tp, _Tp, bool> 00402 { 00403 _GLIBCXX14_CONSTEXPR 00404 bool 00405 operator()(const _Tp& __x, const _Tp& __y) const 00406 { return __x <= __y; } 00407 }; 00408 00409 // Partial specialization of std::greater for pointers. 00410 template<typename _Tp> 00411 struct greater<_Tp*> : public binary_function<_Tp*, _Tp*, bool> 00412 { 00413 _GLIBCXX14_CONSTEXPR bool 00414 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW 00415 { 00416 #if __cplusplus >= 201402L 00417 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 00418 if (__builtin_is_constant_evaluated()) 00419 #else 00420 if (__builtin_constant_p(__x > __y)) 00421 #endif 00422 return __x > __y; 00423 #endif 00424 return (__UINTPTR_TYPE__)__x > (__UINTPTR_TYPE__)__y; 00425 } 00426 }; 00427 00428 // Partial specialization of std::less for pointers. 00429 template<typename _Tp> 00430 struct less<_Tp*> : public binary_function<_Tp*, _Tp*, bool> 00431 { 00432 _GLIBCXX14_CONSTEXPR bool 00433 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW 00434 { 00435 #if __cplusplus >= 201402L 00436 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 00437 if (__builtin_is_constant_evaluated()) 00438 #else 00439 if (__builtin_constant_p(__x < __y)) 00440 #endif 00441 return __x < __y; 00442 #endif 00443 return (__UINTPTR_TYPE__)__x < (__UINTPTR_TYPE__)__y; 00444 } 00445 }; 00446 00447 // Partial specialization of std::greater_equal for pointers. 00448 template<typename _Tp> 00449 struct greater_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool> 00450 { 00451 _GLIBCXX14_CONSTEXPR bool 00452 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW 00453 { 00454 #if __cplusplus >= 201402L 00455 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 00456 if (__builtin_is_constant_evaluated()) 00457 #else 00458 if (__builtin_constant_p(__x >= __y)) 00459 #endif 00460 return __x >= __y; 00461 #endif 00462 return (__UINTPTR_TYPE__)__x >= (__UINTPTR_TYPE__)__y; 00463 } 00464 }; 00465 00466 // Partial specialization of std::less_equal for pointers. 00467 template<typename _Tp> 00468 struct less_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool> 00469 { 00470 _GLIBCXX14_CONSTEXPR bool 00471 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW 00472 { 00473 #if __cplusplus >= 201402L 00474 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 00475 if (__builtin_is_constant_evaluated()) 00476 #else 00477 if (__builtin_constant_p(__x <= __y)) 00478 #endif 00479 return __x <= __y; 00480 #endif 00481 return (__UINTPTR_TYPE__)__x <= (__UINTPTR_TYPE__)__y; 00482 } 00483 }; 00484 00485 #if __cplusplus >= 201402L 00486 /// One of the @link comparison_functors comparison functors@endlink. 00487 template<> 00488 struct equal_to<void> 00489 { 00490 template <typename _Tp, typename _Up> 00491 constexpr auto 00492 operator()(_Tp&& __t, _Up&& __u) const 00493 noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u))) 00494 -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u)) 00495 { return std::forward<_Tp>(__t) == std::forward<_Up>(__u); } 00496 00497 typedef __is_transparent is_transparent; 00498 }; 00499 00500 /// One of the @link comparison_functors comparison functors@endlink. 00501 template<> 00502 struct not_equal_to<void> 00503 { 00504 template <typename _Tp, typename _Up> 00505 constexpr auto 00506 operator()(_Tp&& __t, _Up&& __u) const 00507 noexcept(noexcept(std::forward<_Tp>(__t) != std::forward<_Up>(__u))) 00508 -> decltype(std::forward<_Tp>(__t) != std::forward<_Up>(__u)) 00509 { return std::forward<_Tp>(__t) != std::forward<_Up>(__u); } 00510 00511 typedef __is_transparent is_transparent; 00512 }; 00513 00514 /// One of the @link comparison_functors comparison functors@endlink. 00515 template<> 00516 struct greater<void> 00517 { 00518 template <typename _Tp, typename _Up> 00519 constexpr auto 00520 operator()(_Tp&& __t, _Up&& __u) const 00521 noexcept(noexcept(std::forward<_Tp>(__t) > std::forward<_Up>(__u))) 00522 -> decltype(std::forward<_Tp>(__t) > std::forward<_Up>(__u)) 00523 { 00524 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u), 00525 __ptr_cmp<_Tp, _Up>{}); 00526 } 00527 00528 template<typename _Tp, typename _Up> 00529 constexpr bool 00530 operator()(_Tp* __t, _Up* __u) const noexcept 00531 { return greater<common_type_t<_Tp*, _Up*>>{}(__t, __u); } 00532 00533 typedef __is_transparent is_transparent; 00534 00535 private: 00536 template <typename _Tp, typename _Up> 00537 static constexpr decltype(auto) 00538 _S_cmp(_Tp&& __t, _Up&& __u, false_type) 00539 { return std::forward<_Tp>(__t) > std::forward<_Up>(__u); } 00540 00541 template <typename _Tp, typename _Up> 00542 static constexpr bool 00543 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept 00544 { 00545 return greater<const volatile void*>{}( 00546 static_cast<const volatile void*>(std::forward<_Tp>(__t)), 00547 static_cast<const volatile void*>(std::forward<_Up>(__u))); 00548 } 00549 00550 // True if there is no viable operator> member function. 00551 template<typename _Tp, typename _Up, typename = void> 00552 struct __not_overloaded2 : true_type { }; 00553 00554 // False if we can call T.operator>(U) 00555 template<typename _Tp, typename _Up> 00556 struct __not_overloaded2<_Tp, _Up, __void_t< 00557 decltype(std::declval<_Tp>().operator>(std::declval<_Up>()))>> 00558 : false_type { }; 00559 00560 // True if there is no overloaded operator> for these operands. 00561 template<typename _Tp, typename _Up, typename = void> 00562 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { }; 00563 00564 // False if we can call operator>(T,U) 00565 template<typename _Tp, typename _Up> 00566 struct __not_overloaded<_Tp, _Up, __void_t< 00567 decltype(operator>(std::declval<_Tp>(), std::declval<_Up>()))>> 00568 : false_type { }; 00569 00570 template<typename _Tp, typename _Up> 00571 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>, 00572 is_convertible<_Tp, const volatile void*>, 00573 is_convertible<_Up, const volatile void*>>; 00574 }; 00575 00576 /// One of the @link comparison_functors comparison functors@endlink. 00577 template<> 00578 struct less<void> 00579 { 00580 template <typename _Tp, typename _Up> 00581 constexpr auto 00582 operator()(_Tp&& __t, _Up&& __u) const 00583 noexcept(noexcept(std::forward<_Tp>(__t) < std::forward<_Up>(__u))) 00584 -> decltype(std::forward<_Tp>(__t) < std::forward<_Up>(__u)) 00585 { 00586 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u), 00587 __ptr_cmp<_Tp, _Up>{}); 00588 } 00589 00590 template<typename _Tp, typename _Up> 00591 constexpr bool 00592 operator()(_Tp* __t, _Up* __u) const noexcept 00593 { return less<common_type_t<_Tp*, _Up*>>{}(__t, __u); } 00594 00595 typedef __is_transparent is_transparent; 00596 00597 private: 00598 template <typename _Tp, typename _Up> 00599 static constexpr decltype(auto) 00600 _S_cmp(_Tp&& __t, _Up&& __u, false_type) 00601 { return std::forward<_Tp>(__t) < std::forward<_Up>(__u); } 00602 00603 template <typename _Tp, typename _Up> 00604 static constexpr bool 00605 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept 00606 { 00607 return less<const volatile void*>{}( 00608 static_cast<const volatile void*>(std::forward<_Tp>(__t)), 00609 static_cast<const volatile void*>(std::forward<_Up>(__u))); 00610 } 00611 00612 // True if there is no viable operator< member function. 00613 template<typename _Tp, typename _Up, typename = void> 00614 struct __not_overloaded2 : true_type { }; 00615 00616 // False if we can call T.operator<(U) 00617 template<typename _Tp, typename _Up> 00618 struct __not_overloaded2<_Tp, _Up, __void_t< 00619 decltype(std::declval<_Tp>().operator<(std::declval<_Up>()))>> 00620 : false_type { }; 00621 00622 // True if there is no overloaded operator< for these operands. 00623 template<typename _Tp, typename _Up, typename = void> 00624 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { }; 00625 00626 // False if we can call operator<(T,U) 00627 template<typename _Tp, typename _Up> 00628 struct __not_overloaded<_Tp, _Up, __void_t< 00629 decltype(operator<(std::declval<_Tp>(), std::declval<_Up>()))>> 00630 : false_type { }; 00631 00632 template<typename _Tp, typename _Up> 00633 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>, 00634 is_convertible<_Tp, const volatile void*>, 00635 is_convertible<_Up, const volatile void*>>; 00636 }; 00637 00638 /// One of the @link comparison_functors comparison functors@endlink. 00639 template<> 00640 struct greater_equal<void> 00641 { 00642 template <typename _Tp, typename _Up> 00643 constexpr auto 00644 operator()(_Tp&& __t, _Up&& __u) const 00645 noexcept(noexcept(std::forward<_Tp>(__t) >= std::forward<_Up>(__u))) 00646 -> decltype(std::forward<_Tp>(__t) >= std::forward<_Up>(__u)) 00647 { 00648 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u), 00649 __ptr_cmp<_Tp, _Up>{}); 00650 } 00651 00652 template<typename _Tp, typename _Up> 00653 constexpr bool 00654 operator()(_Tp* __t, _Up* __u) const noexcept 00655 { return greater_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); } 00656 00657 typedef __is_transparent is_transparent; 00658 00659 private: 00660 template <typename _Tp, typename _Up> 00661 static constexpr decltype(auto) 00662 _S_cmp(_Tp&& __t, _Up&& __u, false_type) 00663 { return std::forward<_Tp>(__t) >= std::forward<_Up>(__u); } 00664 00665 template <typename _Tp, typename _Up> 00666 static constexpr bool 00667 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept 00668 { 00669 return greater_equal<const volatile void*>{}( 00670 static_cast<const volatile void*>(std::forward<_Tp>(__t)), 00671 static_cast<const volatile void*>(std::forward<_Up>(__u))); 00672 } 00673 00674 // True if there is no viable operator>= member function. 00675 template<typename _Tp, typename _Up, typename = void> 00676 struct __not_overloaded2 : true_type { }; 00677 00678 // False if we can call T.operator>=(U) 00679 template<typename _Tp, typename _Up> 00680 struct __not_overloaded2<_Tp, _Up, __void_t< 00681 decltype(std::declval<_Tp>().operator>=(std::declval<_Up>()))>> 00682 : false_type { }; 00683 00684 // True if there is no overloaded operator>= for these operands. 00685 template<typename _Tp, typename _Up, typename = void> 00686 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { }; 00687 00688 // False if we can call operator>=(T,U) 00689 template<typename _Tp, typename _Up> 00690 struct __not_overloaded<_Tp, _Up, __void_t< 00691 decltype(operator>=(std::declval<_Tp>(), std::declval<_Up>()))>> 00692 : false_type { }; 00693 00694 template<typename _Tp, typename _Up> 00695 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>, 00696 is_convertible<_Tp, const volatile void*>, 00697 is_convertible<_Up, const volatile void*>>; 00698 }; 00699 00700 /// One of the @link comparison_functors comparison functors@endlink. 00701 template<> 00702 struct less_equal<void> 00703 { 00704 template <typename _Tp, typename _Up> 00705 constexpr auto 00706 operator()(_Tp&& __t, _Up&& __u) const 00707 noexcept(noexcept(std::forward<_Tp>(__t) <= std::forward<_Up>(__u))) 00708 -> decltype(std::forward<_Tp>(__t) <= std::forward<_Up>(__u)) 00709 { 00710 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u), 00711 __ptr_cmp<_Tp, _Up>{}); 00712 } 00713 00714 template<typename _Tp, typename _Up> 00715 constexpr bool 00716 operator()(_Tp* __t, _Up* __u) const noexcept 00717 { return less_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); } 00718 00719 typedef __is_transparent is_transparent; 00720 00721 private: 00722 template <typename _Tp, typename _Up> 00723 static constexpr decltype(auto) 00724 _S_cmp(_Tp&& __t, _Up&& __u, false_type) 00725 { return std::forward<_Tp>(__t) <= std::forward<_Up>(__u); } 00726 00727 template <typename _Tp, typename _Up> 00728 static constexpr bool 00729 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept 00730 { 00731 return less_equal<const volatile void*>{}( 00732 static_cast<const volatile void*>(std::forward<_Tp>(__t)), 00733 static_cast<const volatile void*>(std::forward<_Up>(__u))); 00734 } 00735 00736 // True if there is no viable operator<= member function. 00737 template<typename _Tp, typename _Up, typename = void> 00738 struct __not_overloaded2 : true_type { }; 00739 00740 // False if we can call T.operator<=(U) 00741 template<typename _Tp, typename _Up> 00742 struct __not_overloaded2<_Tp, _Up, __void_t< 00743 decltype(std::declval<_Tp>().operator<=(std::declval<_Up>()))>> 00744 : false_type { }; 00745 00746 // True if there is no overloaded operator<= for these operands. 00747 template<typename _Tp, typename _Up, typename = void> 00748 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { }; 00749 00750 // False if we can call operator<=(T,U) 00751 template<typename _Tp, typename _Up> 00752 struct __not_overloaded<_Tp, _Up, __void_t< 00753 decltype(operator<=(std::declval<_Tp>(), std::declval<_Up>()))>> 00754 : false_type { }; 00755 00756 template<typename _Tp, typename _Up> 00757 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>, 00758 is_convertible<_Tp, const volatile void*>, 00759 is_convertible<_Up, const volatile void*>>; 00760 }; 00761 #endif // C++14 00762 /** @} */ 00763 00764 // 20.3.4 logical operations 00765 /** @defgroup logical_functors Boolean Operations Classes 00766 * @ingroup functors 00767 * 00768 * Here are wrapper functors for Boolean operations: @c &&, @c ||, 00769 * and @c !. 00770 * 00771 * @{ 00772 */ 00773 #if __cplusplus > 201103L 00774 template<typename _Tp = void> 00775 struct logical_and; 00776 00777 template<typename _Tp = void> 00778 struct logical_or; 00779 00780 template<typename _Tp = void> 00781 struct logical_not; 00782 #endif 00783 00784 /// One of the @link logical_functors Boolean operations functors@endlink. 00785 template<typename _Tp> 00786 struct logical_and : public binary_function<_Tp, _Tp, bool> 00787 { 00788 _GLIBCXX14_CONSTEXPR 00789 bool 00790 operator()(const _Tp& __x, const _Tp& __y) const 00791 { return __x && __y; } 00792 }; 00793 00794 /// One of the @link logical_functors Boolean operations functors@endlink. 00795 template<typename _Tp> 00796 struct logical_or : public binary_function<_Tp, _Tp, bool> 00797 { 00798 _GLIBCXX14_CONSTEXPR 00799 bool 00800 operator()(const _Tp& __x, const _Tp& __y) const 00801 { return __x || __y; } 00802 }; 00803 00804 /// One of the @link logical_functors Boolean operations functors@endlink. 00805 template<typename _Tp> 00806 struct logical_not : public unary_function<_Tp, bool> 00807 { 00808 _GLIBCXX14_CONSTEXPR 00809 bool 00810 operator()(const _Tp& __x) const 00811 { return !__x; } 00812 }; 00813 00814 #if __cplusplus > 201103L 00815 /// One of the @link logical_functors Boolean operations functors@endlink. 00816 template<> 00817 struct logical_and<void> 00818 { 00819 template <typename _Tp, typename _Up> 00820 _GLIBCXX14_CONSTEXPR 00821 auto 00822 operator()(_Tp&& __t, _Up&& __u) const 00823 noexcept(noexcept(std::forward<_Tp>(__t) && std::forward<_Up>(__u))) 00824 -> decltype(std::forward<_Tp>(__t) && std::forward<_Up>(__u)) 00825 { return std::forward<_Tp>(__t) && std::forward<_Up>(__u); } 00826 00827 typedef __is_transparent is_transparent; 00828 }; 00829 00830 /// One of the @link logical_functors Boolean operations functors@endlink. 00831 template<> 00832 struct logical_or<void> 00833 { 00834 template <typename _Tp, typename _Up> 00835 _GLIBCXX14_CONSTEXPR 00836 auto 00837 operator()(_Tp&& __t, _Up&& __u) const 00838 noexcept(noexcept(std::forward<_Tp>(__t) || std::forward<_Up>(__u))) 00839 -> decltype(std::forward<_Tp>(__t) || std::forward<_Up>(__u)) 00840 { return std::forward<_Tp>(__t) || std::forward<_Up>(__u); } 00841 00842 typedef __is_transparent is_transparent; 00843 }; 00844 00845 /// One of the @link logical_functors Boolean operations functors@endlink. 00846 template<> 00847 struct logical_not<void> 00848 { 00849 template <typename _Tp> 00850 _GLIBCXX14_CONSTEXPR 00851 auto 00852 operator()(_Tp&& __t) const 00853 noexcept(noexcept(!std::forward<_Tp>(__t))) 00854 -> decltype(!std::forward<_Tp>(__t)) 00855 { return !std::forward<_Tp>(__t); } 00856 00857 typedef __is_transparent is_transparent; 00858 }; 00859 #endif 00860 /** @} */ 00861 00862 #if __cplusplus > 201103L 00863 template<typename _Tp = void> 00864 struct bit_and; 00865 00866 template<typename _Tp = void> 00867 struct bit_or; 00868 00869 template<typename _Tp = void> 00870 struct bit_xor; 00871 00872 template<typename _Tp = void> 00873 struct bit_not; 00874 #endif 00875 00876 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00877 // DR 660. Missing Bitwise Operations. 00878 template<typename _Tp> 00879 struct bit_and : public binary_function<_Tp, _Tp, _Tp> 00880 { 00881 _GLIBCXX14_CONSTEXPR 00882 _Tp 00883 operator()(const _Tp& __x, const _Tp& __y) const 00884 { return __x & __y; } 00885 }; 00886 00887 template<typename _Tp> 00888 struct bit_or : public binary_function<_Tp, _Tp, _Tp> 00889 { 00890 _GLIBCXX14_CONSTEXPR 00891 _Tp 00892 operator()(const _Tp& __x, const _Tp& __y) const 00893 { return __x | __y; } 00894 }; 00895 00896 template<typename _Tp> 00897 struct bit_xor : public binary_function<_Tp, _Tp, _Tp> 00898 { 00899 _GLIBCXX14_CONSTEXPR 00900 _Tp 00901 operator()(const _Tp& __x, const _Tp& __y) const 00902 { return __x ^ __y; } 00903 }; 00904 00905 template<typename _Tp> 00906 struct bit_not : public unary_function<_Tp, _Tp> 00907 { 00908 _GLIBCXX14_CONSTEXPR 00909 _Tp 00910 operator()(const _Tp& __x) const 00911 { return ~__x; } 00912 }; 00913 00914 #if __cplusplus > 201103L 00915 template <> 00916 struct bit_and<void> 00917 { 00918 template <typename _Tp, typename _Up> 00919 _GLIBCXX14_CONSTEXPR 00920 auto 00921 operator()(_Tp&& __t, _Up&& __u) const 00922 noexcept(noexcept(std::forward<_Tp>(__t) & std::forward<_Up>(__u))) 00923 -> decltype(std::forward<_Tp>(__t) & std::forward<_Up>(__u)) 00924 { return std::forward<_Tp>(__t) & std::forward<_Up>(__u); } 00925 00926 typedef __is_transparent is_transparent; 00927 }; 00928 00929 template <> 00930 struct bit_or<void> 00931 { 00932 template <typename _Tp, typename _Up> 00933 _GLIBCXX14_CONSTEXPR 00934 auto 00935 operator()(_Tp&& __t, _Up&& __u) const 00936 noexcept(noexcept(std::forward<_Tp>(__t) | std::forward<_Up>(__u))) 00937 -> decltype(std::forward<_Tp>(__t) | std::forward<_Up>(__u)) 00938 { return std::forward<_Tp>(__t) | std::forward<_Up>(__u); } 00939 00940 typedef __is_transparent is_transparent; 00941 }; 00942 00943 template <> 00944 struct bit_xor<void> 00945 { 00946 template <typename _Tp, typename _Up> 00947 _GLIBCXX14_CONSTEXPR 00948 auto 00949 operator()(_Tp&& __t, _Up&& __u) const 00950 noexcept(noexcept(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u))) 00951 -> decltype(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u)) 00952 { return std::forward<_Tp>(__t) ^ std::forward<_Up>(__u); } 00953 00954 typedef __is_transparent is_transparent; 00955 }; 00956 00957 template <> 00958 struct bit_not<void> 00959 { 00960 template <typename _Tp> 00961 _GLIBCXX14_CONSTEXPR 00962 auto 00963 operator()(_Tp&& __t) const 00964 noexcept(noexcept(~std::forward<_Tp>(__t))) 00965 -> decltype(~std::forward<_Tp>(__t)) 00966 { return ~std::forward<_Tp>(__t); } 00967 00968 typedef __is_transparent is_transparent; 00969 }; 00970 #endif 00971 00972 // 20.3.5 negators 00973 /** @defgroup negators Negators 00974 * @ingroup functors 00975 * 00976 * The functions @c not1 and @c not2 each take a predicate functor 00977 * and return an instance of @c unary_negate or 00978 * @c binary_negate, respectively. These classes are functors whose 00979 * @c operator() performs the stored predicate function and then returns 00980 * the negation of the result. 00981 * 00982 * For example, given a vector of integers and a trivial predicate, 00983 * \code 00984 * struct IntGreaterThanThree 00985 * : public std::unary_function<int, bool> 00986 * { 00987 * bool operator() (int x) { return x > 3; } 00988 * }; 00989 * 00990 * std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree())); 00991 * \endcode 00992 * The call to @c find_if will locate the first index (i) of @c v for which 00993 * <code>!(v[i] > 3)</code> is true. 00994 * 00995 * The not1/unary_negate combination works on predicates taking a single 00996 * argument. The not2/binary_negate combination works on predicates which 00997 * take two arguments. 00998 * 00999 * @{ 01000 */ 01001 /// One of the @link negators negation functors@endlink. 01002 template<typename _Predicate> 01003 class unary_negate 01004 : public unary_function<typename _Predicate::argument_type, bool> 01005 { 01006 protected: 01007 _Predicate _M_pred; 01008 01009 public: 01010 _GLIBCXX14_CONSTEXPR 01011 explicit 01012 unary_negate(const _Predicate& __x) : _M_pred(__x) { } 01013 01014 _GLIBCXX14_CONSTEXPR 01015 bool 01016 operator()(const typename _Predicate::argument_type& __x) const 01017 { return !_M_pred(__x); } 01018 }; 01019 01020 /// One of the @link negators negation functors@endlink. 01021 template<typename _Predicate> 01022 _GLIBCXX14_CONSTEXPR 01023 inline unary_negate<_Predicate> 01024 not1(const _Predicate& __pred) 01025 { return unary_negate<_Predicate>(__pred); } 01026 01027 /// One of the @link negators negation functors@endlink. 01028 template<typename _Predicate> 01029 class binary_negate 01030 : public binary_function<typename _Predicate::first_argument_type, 01031 typename _Predicate::second_argument_type, bool> 01032 { 01033 protected: 01034 _Predicate _M_pred; 01035 01036 public: 01037 _GLIBCXX14_CONSTEXPR 01038 explicit 01039 binary_negate(const _Predicate& __x) : _M_pred(__x) { } 01040 01041 _GLIBCXX14_CONSTEXPR 01042 bool 01043 operator()(const typename _Predicate::first_argument_type& __x, 01044 const typename _Predicate::second_argument_type& __y) const 01045 { return !_M_pred(__x, __y); } 01046 }; 01047 01048 /// One of the @link negators negation functors@endlink. 01049 template<typename _Predicate> 01050 _GLIBCXX14_CONSTEXPR 01051 inline binary_negate<_Predicate> 01052 not2(const _Predicate& __pred) 01053 { return binary_negate<_Predicate>(__pred); } 01054 /** @} */ 01055 01056 // 20.3.7 adaptors pointers functions 01057 /** @defgroup pointer_adaptors Adaptors for pointers to functions 01058 * @ingroup functors 01059 * 01060 * The advantage of function objects over pointers to functions is that 01061 * the objects in the standard library declare nested typedefs describing 01062 * their argument and result types with uniform names (e.g., @c result_type 01063 * from the base classes @c unary_function and @c binary_function). 01064 * Sometimes those typedefs are required, not just optional. 01065 * 01066 * Adaptors are provided to turn pointers to unary (single-argument) and 01067 * binary (double-argument) functions into function objects. The 01068 * long-winded functor @c pointer_to_unary_function is constructed with a 01069 * function pointer @c f, and its @c operator() called with argument @c x 01070 * returns @c f(x). The functor @c pointer_to_binary_function does the same 01071 * thing, but with a double-argument @c f and @c operator(). 01072 * 01073 * The function @c ptr_fun takes a pointer-to-function @c f and constructs 01074 * an instance of the appropriate functor. 01075 * 01076 * @{ 01077 */ 01078 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 01079 template<typename _Arg, typename _Result> 01080 class pointer_to_unary_function : public unary_function<_Arg, _Result> 01081 { 01082 protected: 01083 _Result (*_M_ptr)(_Arg); 01084 01085 public: 01086 pointer_to_unary_function() { } 01087 01088 explicit 01089 pointer_to_unary_function(_Result (*__x)(_Arg)) 01090 : _M_ptr(__x) { } 01091 01092 _Result 01093 operator()(_Arg __x) const 01094 { return _M_ptr(__x); } 01095 }; 01096 01097 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 01098 template<typename _Arg, typename _Result> 01099 inline pointer_to_unary_function<_Arg, _Result> 01100 ptr_fun(_Result (*__x)(_Arg)) 01101 { return pointer_to_unary_function<_Arg, _Result>(__x); } 01102 01103 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 01104 template<typename _Arg1, typename _Arg2, typename _Result> 01105 class pointer_to_binary_function 01106 : public binary_function<_Arg1, _Arg2, _Result> 01107 { 01108 protected: 01109 _Result (*_M_ptr)(_Arg1, _Arg2); 01110 01111 public: 01112 pointer_to_binary_function() { } 01113 01114 explicit 01115 pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2)) 01116 : _M_ptr(__x) { } 01117 01118 _Result 01119 operator()(_Arg1 __x, _Arg2 __y) const 01120 { return _M_ptr(__x, __y); } 01121 }; 01122 01123 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 01124 template<typename _Arg1, typename _Arg2, typename _Result> 01125 inline pointer_to_binary_function<_Arg1, _Arg2, _Result> 01126 ptr_fun(_Result (*__x)(_Arg1, _Arg2)) 01127 { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); } 01128 /** @} */ 01129 01130 template<typename _Tp> 01131 struct _Identity 01132 : public unary_function<_Tp, _Tp> 01133 { 01134 _Tp& 01135 operator()(_Tp& __x) const 01136 { return __x; } 01137 01138 const _Tp& 01139 operator()(const _Tp& __x) const 01140 { return __x; } 01141 }; 01142 01143 // Partial specialization, avoids confusing errors in e.g. std::set<const T>. 01144 template<typename _Tp> struct _Identity<const _Tp> : _Identity<_Tp> { }; 01145 01146 template<typename _Pair> 01147 struct _Select1st 01148 : public unary_function<_Pair, typename _Pair::first_type> 01149 { 01150 typename _Pair::first_type& 01151 operator()(_Pair& __x) const 01152 { return __x.first; } 01153 01154 const typename _Pair::first_type& 01155 operator()(const _Pair& __x) const 01156 { return __x.first; } 01157 01158 #if __cplusplus >= 201103L 01159 template<typename _Pair2> 01160 typename _Pair2::first_type& 01161 operator()(_Pair2& __x) const 01162 { return __x.first; } 01163 01164 template<typename _Pair2> 01165 const typename _Pair2::first_type& 01166 operator()(const _Pair2& __x) const 01167 { return __x.first; } 01168 #endif 01169 }; 01170 01171 template<typename _Pair> 01172 struct _Select2nd 01173 : public unary_function<_Pair, typename _Pair::second_type> 01174 { 01175 typename _Pair::second_type& 01176 operator()(_Pair& __x) const 01177 { return __x.second; } 01178 01179 const typename _Pair::second_type& 01180 operator()(const _Pair& __x) const 01181 { return __x.second; } 01182 }; 01183 01184 // 20.3.8 adaptors pointers members 01185 /** @defgroup memory_adaptors Adaptors for pointers to members 01186 * @ingroup functors 01187 * 01188 * There are a total of 8 = 2^3 function objects in this family. 01189 * (1) Member functions taking no arguments vs member functions taking 01190 * one argument. 01191 * (2) Call through pointer vs call through reference. 01192 * (3) Const vs non-const member function. 01193 * 01194 * All of this complexity is in the function objects themselves. You can 01195 * ignore it by using the helper function mem_fun and mem_fun_ref, 01196 * which create whichever type of adaptor is appropriate. 01197 * 01198 * @{ 01199 */ 01200 /// One of the @link memory_adaptors adaptors for member 01201 /// pointers@endlink. 01202 template<typename _Ret, typename _Tp> 01203 class mem_fun_t : public unary_function<_Tp*, _Ret> 01204 { 01205 public: 01206 explicit 01207 mem_fun_t(_Ret (_Tp::*__pf)()) 01208 : _M_f(__pf) { } 01209 01210 _Ret 01211 operator()(_Tp* __p) const 01212 { return (__p->*_M_f)(); } 01213 01214 private: 01215 _Ret (_Tp::*_M_f)(); 01216 }; 01217 01218 /// One of the @link memory_adaptors adaptors for member 01219 /// pointers@endlink. 01220 template<typename _Ret, typename _Tp> 01221 class const_mem_fun_t : public unary_function<const _Tp*, _Ret> 01222 { 01223 public: 01224 explicit 01225 const_mem_fun_t(_Ret (_Tp::*__pf)() const) 01226 : _M_f(__pf) { } 01227 01228 _Ret 01229 operator()(const _Tp* __p) const 01230 { return (__p->*_M_f)(); } 01231 01232 private: 01233 _Ret (_Tp::*_M_f)() const; 01234 }; 01235 01236 /// One of the @link memory_adaptors adaptors for member 01237 /// pointers@endlink. 01238 template<typename _Ret, typename _Tp> 01239 class mem_fun_ref_t : public unary_function<_Tp, _Ret> 01240 { 01241 public: 01242 explicit 01243 mem_fun_ref_t(_Ret (_Tp::*__pf)()) 01244 : _M_f(__pf) { } 01245 01246 _Ret 01247 operator()(_Tp& __r) const 01248 { return (__r.*_M_f)(); } 01249 01250 private: 01251 _Ret (_Tp::*_M_f)(); 01252 }; 01253 01254 /// One of the @link memory_adaptors adaptors for member 01255 /// pointers@endlink. 01256 template<typename _Ret, typename _Tp> 01257 class const_mem_fun_ref_t : public unary_function<_Tp, _Ret> 01258 { 01259 public: 01260 explicit 01261 const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) 01262 : _M_f(__pf) { } 01263 01264 _Ret 01265 operator()(const _Tp& __r) const 01266 { return (__r.*_M_f)(); } 01267 01268 private: 01269 _Ret (_Tp::*_M_f)() const; 01270 }; 01271 01272 /// One of the @link memory_adaptors adaptors for member 01273 /// pointers@endlink. 01274 template<typename _Ret, typename _Tp, typename _Arg> 01275 class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret> 01276 { 01277 public: 01278 explicit 01279 mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) 01280 : _M_f(__pf) { } 01281 01282 _Ret 01283 operator()(_Tp* __p, _Arg __x) const 01284 { return (__p->*_M_f)(__x); } 01285 01286 private: 01287 _Ret (_Tp::*_M_f)(_Arg); 01288 }; 01289 01290 /// One of the @link memory_adaptors adaptors for member 01291 /// pointers@endlink. 01292 template<typename _Ret, typename _Tp, typename _Arg> 01293 class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret> 01294 { 01295 public: 01296 explicit 01297 const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) 01298 : _M_f(__pf) { } 01299 01300 _Ret 01301 operator()(const _Tp* __p, _Arg __x) const 01302 { return (__p->*_M_f)(__x); } 01303 01304 private: 01305 _Ret (_Tp::*_M_f)(_Arg) const; 01306 }; 01307 01308 /// One of the @link memory_adaptors adaptors for member 01309 /// pointers@endlink. 01310 template<typename _Ret, typename _Tp, typename _Arg> 01311 class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret> 01312 { 01313 public: 01314 explicit 01315 mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) 01316 : _M_f(__pf) { } 01317 01318 _Ret 01319 operator()(_Tp& __r, _Arg __x) const 01320 { return (__r.*_M_f)(__x); } 01321 01322 private: 01323 _Ret (_Tp::*_M_f)(_Arg); 01324 }; 01325 01326 /// One of the @link memory_adaptors adaptors for member 01327 /// pointers@endlink. 01328 template<typename _Ret, typename _Tp, typename _Arg> 01329 class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret> 01330 { 01331 public: 01332 explicit 01333 const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) 01334 : _M_f(__pf) { } 01335 01336 _Ret 01337 operator()(const _Tp& __r, _Arg __x) const 01338 { return (__r.*_M_f)(__x); } 01339 01340 private: 01341 _Ret (_Tp::*_M_f)(_Arg) const; 01342 }; 01343 01344 // Mem_fun adaptor helper functions. There are only two: 01345 // mem_fun and mem_fun_ref. 01346 template<typename _Ret, typename _Tp> 01347 inline mem_fun_t<_Ret, _Tp> 01348 mem_fun(_Ret (_Tp::*__f)()) 01349 { return mem_fun_t<_Ret, _Tp>(__f); } 01350 01351 template<typename _Ret, typename _Tp> 01352 inline const_mem_fun_t<_Ret, _Tp> 01353 mem_fun(_Ret (_Tp::*__f)() const) 01354 { return const_mem_fun_t<_Ret, _Tp>(__f); } 01355 01356 template<typename _Ret, typename _Tp> 01357 inline mem_fun_ref_t<_Ret, _Tp> 01358 mem_fun_ref(_Ret (_Tp::*__f)()) 01359 { return mem_fun_ref_t<_Ret, _Tp>(__f); } 01360 01361 template<typename _Ret, typename _Tp> 01362 inline const_mem_fun_ref_t<_Ret, _Tp> 01363 mem_fun_ref(_Ret (_Tp::*__f)() const) 01364 { return const_mem_fun_ref_t<_Ret, _Tp>(__f); } 01365 01366 template<typename _Ret, typename _Tp, typename _Arg> 01367 inline mem_fun1_t<_Ret, _Tp, _Arg> 01368 mem_fun(_Ret (_Tp::*__f)(_Arg)) 01369 { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); } 01370 01371 template<typename _Ret, typename _Tp, typename _Arg> 01372 inline const_mem_fun1_t<_Ret, _Tp, _Arg> 01373 mem_fun(_Ret (_Tp::*__f)(_Arg) const) 01374 { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); } 01375 01376 template<typename _Ret, typename _Tp, typename _Arg> 01377 inline mem_fun1_ref_t<_Ret, _Tp, _Arg> 01378 mem_fun_ref(_Ret (_Tp::*__f)(_Arg)) 01379 { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); } 01380 01381 template<typename _Ret, typename _Tp, typename _Arg> 01382 inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg> 01383 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const) 01384 { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); } 01385 01386 /** @} */ 01387 01388 _GLIBCXX_END_NAMESPACE_VERSION 01389 } // namespace 01390 01391 #if (__cplusplus < 201103L) || _GLIBCXX_USE_DEPRECATED 01392 # include <backward/binders.h> 01393 #endif 01394 01395 #endif /* _STL_FUNCTION_H */