libstdc++
stl_function.h
Go to the documentation of this file.
00001 // Functor implementations -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2017 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 #if __cplusplus > 201103L
00410   /// One of the @link comparison_functors comparison functors@endlink.
00411   template<>
00412     struct equal_to<void>
00413     {
00414       template <typename _Tp, typename _Up>
00415         _GLIBCXX14_CONSTEXPR
00416         auto
00417         operator()(_Tp&& __t, _Up&& __u) const
00418         noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
00419         -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u))
00420         { return std::forward<_Tp>(__t) == std::forward<_Up>(__u); }
00421 
00422       typedef __is_transparent is_transparent;
00423     };
00424 
00425   /// One of the @link comparison_functors comparison functors@endlink.
00426   template<>
00427     struct not_equal_to<void>
00428     {
00429       template <typename _Tp, typename _Up>
00430         _GLIBCXX14_CONSTEXPR
00431         auto
00432         operator()(_Tp&& __t, _Up&& __u) const
00433         noexcept(noexcept(std::forward<_Tp>(__t) != std::forward<_Up>(__u)))
00434         -> decltype(std::forward<_Tp>(__t) != std::forward<_Up>(__u))
00435         { return std::forward<_Tp>(__t) != std::forward<_Up>(__u); }
00436 
00437       typedef __is_transparent is_transparent;
00438     };
00439 
00440   /// One of the @link comparison_functors comparison functors@endlink.
00441   template<>
00442     struct greater<void>
00443     {
00444       template <typename _Tp, typename _Up>
00445         _GLIBCXX14_CONSTEXPR
00446         auto
00447         operator()(_Tp&& __t, _Up&& __u) const
00448         noexcept(noexcept(std::forward<_Tp>(__t) > std::forward<_Up>(__u)))
00449         -> decltype(std::forward<_Tp>(__t) > std::forward<_Up>(__u))
00450         { return std::forward<_Tp>(__t) > std::forward<_Up>(__u); }
00451 
00452       typedef __is_transparent is_transparent;
00453     };
00454 
00455   /// One of the @link comparison_functors comparison functors@endlink.
00456   template<>
00457     struct less<void>
00458     {
00459       template <typename _Tp, typename _Up>
00460         _GLIBCXX14_CONSTEXPR
00461         auto
00462         operator()(_Tp&& __t, _Up&& __u) const
00463         noexcept(noexcept(std::forward<_Tp>(__t) < std::forward<_Up>(__u)))
00464         -> decltype(std::forward<_Tp>(__t) < std::forward<_Up>(__u))
00465         { return std::forward<_Tp>(__t) < std::forward<_Up>(__u); }
00466 
00467       typedef __is_transparent is_transparent;
00468     };
00469 
00470   /// One of the @link comparison_functors comparison functors@endlink.
00471   template<>
00472     struct greater_equal<void>
00473     {
00474       template <typename _Tp, typename _Up>
00475         _GLIBCXX14_CONSTEXPR
00476         auto
00477         operator()(_Tp&& __t, _Up&& __u) const
00478         noexcept(noexcept(std::forward<_Tp>(__t) >= std::forward<_Up>(__u)))
00479         -> decltype(std::forward<_Tp>(__t) >= std::forward<_Up>(__u))
00480         { return std::forward<_Tp>(__t) >= std::forward<_Up>(__u); }
00481 
00482       typedef __is_transparent is_transparent;
00483     };
00484 
00485   /// One of the @link comparison_functors comparison functors@endlink.
00486   template<>
00487     struct less_equal<void>
00488     {
00489       template <typename _Tp, typename _Up>
00490         _GLIBCXX14_CONSTEXPR
00491         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 #endif
00500   /** @}  */
00501 
00502   // 20.3.4 logical operations
00503   /** @defgroup logical_functors Boolean Operations Classes
00504    * @ingroup functors
00505    *
00506    *  Here are wrapper functors for Boolean operations: @c &&, @c ||,
00507    *  and @c !.
00508    *
00509    *  @{
00510    */
00511 #if __cplusplus > 201103L
00512   template<typename _Tp = void>
00513     struct logical_and;
00514 
00515   template<typename _Tp = void>
00516     struct logical_or;
00517 
00518   template<typename _Tp = void>
00519     struct logical_not;
00520 #endif
00521 
00522   /// One of the @link logical_functors Boolean operations functors@endlink.
00523   template<typename _Tp>
00524     struct logical_and : public binary_function<_Tp, _Tp, bool>
00525     {
00526       _GLIBCXX14_CONSTEXPR
00527       bool
00528       operator()(const _Tp& __x, const _Tp& __y) const
00529       { return __x && __y; }
00530     };
00531 
00532   /// One of the @link logical_functors Boolean operations functors@endlink.
00533   template<typename _Tp>
00534     struct logical_or : public binary_function<_Tp, _Tp, bool>
00535     {
00536       _GLIBCXX14_CONSTEXPR
00537       bool
00538       operator()(const _Tp& __x, const _Tp& __y) const
00539       { return __x || __y; }
00540     };
00541 
00542   /// One of the @link logical_functors Boolean operations functors@endlink.
00543   template<typename _Tp>
00544     struct logical_not : public unary_function<_Tp, bool>
00545     {
00546       _GLIBCXX14_CONSTEXPR
00547       bool
00548       operator()(const _Tp& __x) const
00549       { return !__x; }
00550     };
00551 
00552 #if __cplusplus > 201103L
00553   /// One of the @link logical_functors Boolean operations functors@endlink.
00554   template<>
00555     struct logical_and<void>
00556     {
00557       template <typename _Tp, typename _Up>
00558         _GLIBCXX14_CONSTEXPR
00559         auto
00560         operator()(_Tp&& __t, _Up&& __u) const
00561         noexcept(noexcept(std::forward<_Tp>(__t) && std::forward<_Up>(__u)))
00562         -> decltype(std::forward<_Tp>(__t) && std::forward<_Up>(__u))
00563         { return std::forward<_Tp>(__t) && std::forward<_Up>(__u); }
00564 
00565       typedef __is_transparent is_transparent;
00566     };
00567 
00568   /// One of the @link logical_functors Boolean operations functors@endlink.
00569   template<>
00570     struct logical_or<void>
00571     {
00572       template <typename _Tp, typename _Up>
00573         _GLIBCXX14_CONSTEXPR
00574         auto
00575         operator()(_Tp&& __t, _Up&& __u) const
00576         noexcept(noexcept(std::forward<_Tp>(__t) || std::forward<_Up>(__u)))
00577         -> decltype(std::forward<_Tp>(__t) || std::forward<_Up>(__u))
00578         { return std::forward<_Tp>(__t) || std::forward<_Up>(__u); }
00579 
00580       typedef __is_transparent is_transparent;
00581     };
00582 
00583   /// One of the @link logical_functors Boolean operations functors@endlink.
00584   template<>
00585     struct logical_not<void>
00586     {
00587       template <typename _Tp>
00588         _GLIBCXX14_CONSTEXPR
00589         auto
00590         operator()(_Tp&& __t) const
00591         noexcept(noexcept(!std::forward<_Tp>(__t)))
00592         -> decltype(!std::forward<_Tp>(__t))
00593         { return !std::forward<_Tp>(__t); }
00594 
00595       typedef __is_transparent is_transparent;
00596     };
00597 #endif
00598   /** @}  */
00599 
00600 #if __cplusplus > 201103L
00601   template<typename _Tp = void>
00602     struct bit_and;
00603 
00604   template<typename _Tp = void>
00605     struct bit_or;
00606 
00607   template<typename _Tp = void>
00608     struct bit_xor;
00609 
00610   template<typename _Tp = void>
00611     struct bit_not;
00612 #endif
00613 
00614   // _GLIBCXX_RESOLVE_LIB_DEFECTS
00615   // DR 660. Missing Bitwise Operations.
00616   template<typename _Tp>
00617     struct bit_and : public binary_function<_Tp, _Tp, _Tp>
00618     {
00619       _GLIBCXX14_CONSTEXPR
00620       _Tp
00621       operator()(const _Tp& __x, const _Tp& __y) const
00622       { return __x & __y; }
00623     };
00624 
00625   template<typename _Tp>
00626     struct bit_or : public binary_function<_Tp, _Tp, _Tp>
00627     {
00628       _GLIBCXX14_CONSTEXPR
00629       _Tp
00630       operator()(const _Tp& __x, const _Tp& __y) const
00631       { return __x | __y; }
00632     };
00633 
00634   template<typename _Tp>
00635     struct bit_xor : public binary_function<_Tp, _Tp, _Tp>
00636     {
00637       _GLIBCXX14_CONSTEXPR
00638       _Tp
00639       operator()(const _Tp& __x, const _Tp& __y) const
00640       { return __x ^ __y; }
00641     };
00642 
00643   template<typename _Tp>
00644     struct bit_not : public unary_function<_Tp, _Tp>
00645     {
00646     _GLIBCXX14_CONSTEXPR
00647       _Tp
00648       operator()(const _Tp& __x) const
00649       { return ~__x; }
00650     };
00651 
00652 #if __cplusplus > 201103L
00653   template <>
00654     struct bit_and<void>
00655     {
00656       template <typename _Tp, typename _Up>
00657         _GLIBCXX14_CONSTEXPR
00658         auto
00659         operator()(_Tp&& __t, _Up&& __u) const
00660         noexcept(noexcept(std::forward<_Tp>(__t) & std::forward<_Up>(__u)))
00661         -> decltype(std::forward<_Tp>(__t) & std::forward<_Up>(__u))
00662         { return std::forward<_Tp>(__t) & std::forward<_Up>(__u); }
00663 
00664       typedef __is_transparent is_transparent;
00665     };
00666 
00667   template <>
00668     struct bit_or<void>
00669     {
00670       template <typename _Tp, typename _Up>
00671         _GLIBCXX14_CONSTEXPR
00672         auto
00673         operator()(_Tp&& __t, _Up&& __u) const
00674         noexcept(noexcept(std::forward<_Tp>(__t) | std::forward<_Up>(__u)))
00675         -> decltype(std::forward<_Tp>(__t) | std::forward<_Up>(__u))
00676         { return std::forward<_Tp>(__t) | std::forward<_Up>(__u); }
00677 
00678       typedef __is_transparent is_transparent;
00679     };
00680 
00681   template <>
00682     struct bit_xor<void>
00683     {
00684       template <typename _Tp, typename _Up>
00685         _GLIBCXX14_CONSTEXPR
00686         auto
00687         operator()(_Tp&& __t, _Up&& __u) const
00688         noexcept(noexcept(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u)))
00689         -> decltype(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u))
00690         { return std::forward<_Tp>(__t) ^ std::forward<_Up>(__u); }
00691 
00692       typedef __is_transparent is_transparent;
00693     };
00694 
00695   template <>
00696     struct bit_not<void>
00697     {
00698       template <typename _Tp>
00699         _GLIBCXX14_CONSTEXPR
00700         auto
00701         operator()(_Tp&& __t) const
00702         noexcept(noexcept(~std::forward<_Tp>(__t)))
00703         -> decltype(~std::forward<_Tp>(__t))
00704         { return ~std::forward<_Tp>(__t); }
00705 
00706       typedef __is_transparent is_transparent;
00707     };
00708 #endif
00709 
00710   // 20.3.5 negators
00711   /** @defgroup negators Negators
00712    * @ingroup functors
00713    *
00714    *  The functions @c not1 and @c not2 each take a predicate functor
00715    *  and return an instance of @c unary_negate or
00716    *  @c binary_negate, respectively.  These classes are functors whose
00717    *  @c operator() performs the stored predicate function and then returns
00718    *  the negation of the result.
00719    *
00720    *  For example, given a vector of integers and a trivial predicate,
00721    *  \code
00722    *  struct IntGreaterThanThree
00723    *    : public std::unary_function<int, bool>
00724    *  {
00725    *      bool operator() (int x) { return x > 3; }
00726    *  };
00727    *
00728    *  std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
00729    *  \endcode
00730    *  The call to @c find_if will locate the first index (i) of @c v for which
00731    *  <code>!(v[i] > 3)</code> is true.
00732    *
00733    *  The not1/unary_negate combination works on predicates taking a single
00734    *  argument.  The not2/binary_negate combination works on predicates which
00735    *  take two arguments.
00736    *
00737    *  @{
00738    */
00739   /// One of the @link negators negation functors@endlink.
00740   template<typename _Predicate>
00741     class unary_negate
00742     : public unary_function<typename _Predicate::argument_type, bool>
00743     {
00744     protected:
00745       _Predicate _M_pred;
00746 
00747     public:
00748       _GLIBCXX14_CONSTEXPR
00749       explicit
00750       unary_negate(const _Predicate& __x) : _M_pred(__x) { }
00751 
00752       _GLIBCXX14_CONSTEXPR
00753       bool
00754       operator()(const typename _Predicate::argument_type& __x) const
00755       { return !_M_pred(__x); }
00756     };
00757 
00758   /// One of the @link negators negation functors@endlink.
00759   template<typename _Predicate>
00760     _GLIBCXX14_CONSTEXPR
00761     inline unary_negate<_Predicate>
00762     not1(const _Predicate& __pred)
00763     { return unary_negate<_Predicate>(__pred); }
00764 
00765   /// One of the @link negators negation functors@endlink.
00766   template<typename _Predicate>
00767     class binary_negate
00768     : public binary_function<typename _Predicate::first_argument_type,
00769                              typename _Predicate::second_argument_type, bool>
00770     {
00771     protected:
00772       _Predicate _M_pred;
00773 
00774     public:
00775       _GLIBCXX14_CONSTEXPR
00776       explicit
00777       binary_negate(const _Predicate& __x) : _M_pred(__x) { }
00778 
00779       _GLIBCXX14_CONSTEXPR
00780       bool
00781       operator()(const typename _Predicate::first_argument_type& __x,
00782                  const typename _Predicate::second_argument_type& __y) const
00783       { return !_M_pred(__x, __y); }
00784     };
00785 
00786   /// One of the @link negators negation functors@endlink.
00787   template<typename _Predicate>
00788     _GLIBCXX14_CONSTEXPR
00789     inline binary_negate<_Predicate>
00790     not2(const _Predicate& __pred)
00791     { return binary_negate<_Predicate>(__pred); }
00792   /** @}  */
00793 
00794   // 20.3.7 adaptors pointers functions
00795   /** @defgroup pointer_adaptors Adaptors for pointers to functions
00796    * @ingroup functors
00797    *
00798    *  The advantage of function objects over pointers to functions is that
00799    *  the objects in the standard library declare nested typedefs describing
00800    *  their argument and result types with uniform names (e.g., @c result_type
00801    *  from the base classes @c unary_function and @c binary_function).
00802    *  Sometimes those typedefs are required, not just optional.
00803    *
00804    *  Adaptors are provided to turn pointers to unary (single-argument) and
00805    *  binary (double-argument) functions into function objects.  The
00806    *  long-winded functor @c pointer_to_unary_function is constructed with a
00807    *  function pointer @c f, and its @c operator() called with argument @c x
00808    *  returns @c f(x).  The functor @c pointer_to_binary_function does the same
00809    *  thing, but with a double-argument @c f and @c operator().
00810    *
00811    *  The function @c ptr_fun takes a pointer-to-function @c f and constructs
00812    *  an instance of the appropriate functor.
00813    *
00814    *  @{
00815    */
00816   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
00817   template<typename _Arg, typename _Result>
00818     class pointer_to_unary_function : public unary_function<_Arg, _Result>
00819     {
00820     protected:
00821       _Result (*_M_ptr)(_Arg);
00822 
00823     public:
00824       pointer_to_unary_function() { }
00825 
00826       explicit
00827       pointer_to_unary_function(_Result (*__x)(_Arg))
00828       : _M_ptr(__x) { }
00829 
00830       _Result
00831       operator()(_Arg __x) const
00832       { return _M_ptr(__x); }
00833     };
00834 
00835   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
00836   template<typename _Arg, typename _Result>
00837     inline pointer_to_unary_function<_Arg, _Result>
00838     ptr_fun(_Result (*__x)(_Arg))
00839     { return pointer_to_unary_function<_Arg, _Result>(__x); }
00840 
00841   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
00842   template<typename _Arg1, typename _Arg2, typename _Result>
00843     class pointer_to_binary_function
00844     : public binary_function<_Arg1, _Arg2, _Result>
00845     {
00846     protected:
00847       _Result (*_M_ptr)(_Arg1, _Arg2);
00848 
00849     public:
00850       pointer_to_binary_function() { }
00851 
00852       explicit
00853       pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
00854       : _M_ptr(__x) { }
00855 
00856       _Result
00857       operator()(_Arg1 __x, _Arg2 __y) const
00858       { return _M_ptr(__x, __y); }
00859     };
00860 
00861   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
00862   template<typename _Arg1, typename _Arg2, typename _Result>
00863     inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
00864     ptr_fun(_Result (*__x)(_Arg1, _Arg2))
00865     { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
00866   /** @}  */
00867 
00868   template<typename _Tp>
00869     struct _Identity
00870     : public unary_function<_Tp,_Tp>
00871     {
00872       _Tp&
00873       operator()(_Tp& __x) const
00874       { return __x; }
00875 
00876       const _Tp&
00877       operator()(const _Tp& __x) const
00878       { return __x; }
00879     };
00880 
00881   template<typename _Pair>
00882     struct _Select1st
00883     : public unary_function<_Pair, typename _Pair::first_type>
00884     {
00885       typename _Pair::first_type&
00886       operator()(_Pair& __x) const
00887       { return __x.first; }
00888 
00889       const typename _Pair::first_type&
00890       operator()(const _Pair& __x) const
00891       { return __x.first; }
00892 
00893 #if __cplusplus >= 201103L
00894       template<typename _Pair2>
00895         typename _Pair2::first_type&
00896         operator()(_Pair2& __x) const
00897         { return __x.first; }
00898 
00899       template<typename _Pair2>
00900         const typename _Pair2::first_type&
00901         operator()(const _Pair2& __x) const
00902         { return __x.first; }
00903 #endif
00904     };
00905 
00906   template<typename _Pair>
00907     struct _Select2nd
00908     : public unary_function<_Pair, typename _Pair::second_type>
00909     {
00910       typename _Pair::second_type&
00911       operator()(_Pair& __x) const
00912       { return __x.second; }
00913 
00914       const typename _Pair::second_type&
00915       operator()(const _Pair& __x) const
00916       { return __x.second; }
00917     };
00918 
00919   // 20.3.8 adaptors pointers members
00920   /** @defgroup memory_adaptors Adaptors for pointers to members
00921    * @ingroup functors
00922    *
00923    *  There are a total of 8 = 2^3 function objects in this family.
00924    *   (1) Member functions taking no arguments vs member functions taking
00925    *        one argument.
00926    *   (2) Call through pointer vs call through reference.
00927    *   (3) Const vs non-const member function.
00928    *
00929    *  All of this complexity is in the function objects themselves.  You can
00930    *   ignore it by using the helper function mem_fun and mem_fun_ref,
00931    *   which create whichever type of adaptor is appropriate.
00932    *
00933    *  @{
00934    */
00935   /// One of the @link memory_adaptors adaptors for member
00936   /// pointers@endlink.
00937   template<typename _Ret, typename _Tp>
00938     class mem_fun_t : public unary_function<_Tp*, _Ret>
00939     {
00940     public:
00941       explicit
00942       mem_fun_t(_Ret (_Tp::*__pf)())
00943       : _M_f(__pf) { }
00944 
00945       _Ret
00946       operator()(_Tp* __p) const
00947       { return (__p->*_M_f)(); }
00948 
00949     private:
00950       _Ret (_Tp::*_M_f)();
00951     };
00952 
00953   /// One of the @link memory_adaptors adaptors for member
00954   /// pointers@endlink.
00955   template<typename _Ret, typename _Tp>
00956     class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
00957     {
00958     public:
00959       explicit
00960       const_mem_fun_t(_Ret (_Tp::*__pf)() const)
00961       : _M_f(__pf) { }
00962 
00963       _Ret
00964       operator()(const _Tp* __p) const
00965       { return (__p->*_M_f)(); }
00966 
00967     private:
00968       _Ret (_Tp::*_M_f)() const;
00969     };
00970 
00971   /// One of the @link memory_adaptors adaptors for member
00972   /// pointers@endlink.
00973   template<typename _Ret, typename _Tp>
00974     class mem_fun_ref_t : public unary_function<_Tp, _Ret>
00975     {
00976     public:
00977       explicit
00978       mem_fun_ref_t(_Ret (_Tp::*__pf)())
00979       : _M_f(__pf) { }
00980 
00981       _Ret
00982       operator()(_Tp& __r) const
00983       { return (__r.*_M_f)(); }
00984 
00985     private:
00986       _Ret (_Tp::*_M_f)();
00987   };
00988 
00989   /// One of the @link memory_adaptors adaptors for member
00990   /// pointers@endlink.
00991   template<typename _Ret, typename _Tp>
00992     class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
00993     {
00994     public:
00995       explicit
00996       const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
00997       : _M_f(__pf) { }
00998 
00999       _Ret
01000       operator()(const _Tp& __r) const
01001       { return (__r.*_M_f)(); }
01002 
01003     private:
01004       _Ret (_Tp::*_M_f)() const;
01005     };
01006 
01007   /// One of the @link memory_adaptors adaptors for member
01008   /// pointers@endlink.
01009   template<typename _Ret, typename _Tp, typename _Arg>
01010     class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
01011     {
01012     public:
01013       explicit
01014       mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
01015       : _M_f(__pf) { }
01016 
01017       _Ret
01018       operator()(_Tp* __p, _Arg __x) const
01019       { return (__p->*_M_f)(__x); }
01020 
01021     private:
01022       _Ret (_Tp::*_M_f)(_Arg);
01023     };
01024 
01025   /// One of the @link memory_adaptors adaptors for member
01026   /// pointers@endlink.
01027   template<typename _Ret, typename _Tp, typename _Arg>
01028     class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
01029     {
01030     public:
01031       explicit
01032       const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
01033       : _M_f(__pf) { }
01034 
01035       _Ret
01036       operator()(const _Tp* __p, _Arg __x) const
01037       { return (__p->*_M_f)(__x); }
01038 
01039     private:
01040       _Ret (_Tp::*_M_f)(_Arg) const;
01041     };
01042 
01043   /// One of the @link memory_adaptors adaptors for member
01044   /// pointers@endlink.
01045   template<typename _Ret, typename _Tp, typename _Arg>
01046     class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
01047     {
01048     public:
01049       explicit
01050       mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
01051       : _M_f(__pf) { }
01052 
01053       _Ret
01054       operator()(_Tp& __r, _Arg __x) const
01055       { return (__r.*_M_f)(__x); }
01056 
01057     private:
01058       _Ret (_Tp::*_M_f)(_Arg);
01059     };
01060 
01061   /// One of the @link memory_adaptors adaptors for member
01062   /// pointers@endlink.
01063   template<typename _Ret, typename _Tp, typename _Arg>
01064     class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
01065     {
01066     public:
01067       explicit
01068       const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
01069       : _M_f(__pf) { }
01070 
01071       _Ret
01072       operator()(const _Tp& __r, _Arg __x) const
01073       { return (__r.*_M_f)(__x); }
01074 
01075     private:
01076       _Ret (_Tp::*_M_f)(_Arg) const;
01077     };
01078 
01079   // Mem_fun adaptor helper functions.  There are only two:
01080   // mem_fun and mem_fun_ref.
01081   template<typename _Ret, typename _Tp>
01082     inline mem_fun_t<_Ret, _Tp>
01083     mem_fun(_Ret (_Tp::*__f)())
01084     { return mem_fun_t<_Ret, _Tp>(__f); }
01085 
01086   template<typename _Ret, typename _Tp>
01087     inline const_mem_fun_t<_Ret, _Tp>
01088     mem_fun(_Ret (_Tp::*__f)() const)
01089     { return const_mem_fun_t<_Ret, _Tp>(__f); }
01090 
01091   template<typename _Ret, typename _Tp>
01092     inline mem_fun_ref_t<_Ret, _Tp>
01093     mem_fun_ref(_Ret (_Tp::*__f)())
01094     { return mem_fun_ref_t<_Ret, _Tp>(__f); }
01095 
01096   template<typename _Ret, typename _Tp>
01097     inline const_mem_fun_ref_t<_Ret, _Tp>
01098     mem_fun_ref(_Ret (_Tp::*__f)() const)
01099     { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
01100 
01101   template<typename _Ret, typename _Tp, typename _Arg>
01102     inline mem_fun1_t<_Ret, _Tp, _Arg>
01103     mem_fun(_Ret (_Tp::*__f)(_Arg))
01104     { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
01105 
01106   template<typename _Ret, typename _Tp, typename _Arg>
01107     inline const_mem_fun1_t<_Ret, _Tp, _Arg>
01108     mem_fun(_Ret (_Tp::*__f)(_Arg) const)
01109     { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
01110 
01111   template<typename _Ret, typename _Tp, typename _Arg>
01112     inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
01113     mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
01114     { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
01115 
01116   template<typename _Ret, typename _Tp, typename _Arg>
01117     inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
01118     mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
01119     { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
01120 
01121   /** @}  */
01122 
01123 _GLIBCXX_END_NAMESPACE_VERSION
01124 } // namespace
01125 
01126 #if (__cplusplus < 201103L) || _GLIBCXX_USE_DEPRECATED
01127 # include <backward/binders.h>
01128 #endif
01129 
01130 #endif /* _STL_FUNCTION_H */