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