xref: /netbsd-src/external/gpl3/gcc/dist/libstdc++-v3/include/bits/stl_function.h (revision b1e838363e3c6fc78a55519254d99869742dd33c)
14fee23f9Smrg // Functor implementations -*- C++ -*-
24fee23f9Smrg 
3*b1e83836Smrg // Copyright (C) 2001-2022 Free Software Foundation, Inc.
44fee23f9Smrg //
54fee23f9Smrg // This file is part of the GNU ISO C++ Library.  This library is free
64fee23f9Smrg // software; you can redistribute it and/or modify it under the
74fee23f9Smrg // terms of the GNU General Public License as published by the
84fee23f9Smrg // Free Software Foundation; either version 3, or (at your option)
94fee23f9Smrg // any later version.
104fee23f9Smrg 
114fee23f9Smrg // This library is distributed in the hope that it will be useful,
124fee23f9Smrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
134fee23f9Smrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
144fee23f9Smrg // GNU General Public License for more details.
154fee23f9Smrg 
164fee23f9Smrg // Under Section 7 of GPL version 3, you are granted additional
174fee23f9Smrg // permissions described in the GCC Runtime Library Exception, version
184fee23f9Smrg // 3.1, as published by the Free Software Foundation.
194fee23f9Smrg 
204fee23f9Smrg // You should have received a copy of the GNU General Public License and
214fee23f9Smrg // a copy of the GCC Runtime Library Exception along with this program;
224fee23f9Smrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
234fee23f9Smrg // <http://www.gnu.org/licenses/>.
244fee23f9Smrg 
254fee23f9Smrg /*
264fee23f9Smrg  *
274fee23f9Smrg  * Copyright (c) 1994
284fee23f9Smrg  * Hewlett-Packard Company
294fee23f9Smrg  *
304fee23f9Smrg  * Permission to use, copy, modify, distribute and sell this software
314fee23f9Smrg  * and its documentation for any purpose is hereby granted without fee,
324fee23f9Smrg  * provided that the above copyright notice appear in all copies and
334fee23f9Smrg  * that both that copyright notice and this permission notice appear
344fee23f9Smrg  * in supporting documentation.  Hewlett-Packard Company makes no
354fee23f9Smrg  * representations about the suitability of this software for any
364fee23f9Smrg  * purpose.  It is provided "as is" without express or implied warranty.
374fee23f9Smrg  *
384fee23f9Smrg  *
394fee23f9Smrg  * Copyright (c) 1996-1998
404fee23f9Smrg  * Silicon Graphics Computer Systems, Inc.
414fee23f9Smrg  *
424fee23f9Smrg  * Permission to use, copy, modify, distribute and sell this software
434fee23f9Smrg  * and its documentation for any purpose is hereby granted without fee,
444fee23f9Smrg  * provided that the above copyright notice appear in all copies and
454fee23f9Smrg  * that both that copyright notice and this permission notice appear
464fee23f9Smrg  * in supporting documentation.  Silicon Graphics makes no
474fee23f9Smrg  * representations about the suitability of this software for any
484fee23f9Smrg  * purpose.  It is provided "as is" without express or implied warranty.
494fee23f9Smrg  */
504fee23f9Smrg 
5148fb7bfaSmrg /** @file bits/stl_function.h
524fee23f9Smrg  *  This is an internal header file, included by other library headers.
5348fb7bfaSmrg  *  Do not attempt to use it directly. @headername{functional}
544fee23f9Smrg  */
554fee23f9Smrg 
564fee23f9Smrg #ifndef _STL_FUNCTION_H
574fee23f9Smrg #define _STL_FUNCTION_H 1
584fee23f9Smrg 
594d5abbe8Smrg #if __cplusplus > 201103L
604d5abbe8Smrg #include <bits/move.h>
614d5abbe8Smrg #endif
624d5abbe8Smrg 
_GLIBCXX_VISIBILITY(default)6348fb7bfaSmrg namespace std _GLIBCXX_VISIBILITY(default)
6448fb7bfaSmrg {
6548fb7bfaSmrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
664fee23f9Smrg 
674fee23f9Smrg   // 20.3.1 base classes
684fee23f9Smrg   /** @defgroup functors Function Objects
694fee23f9Smrg    *  @ingroup utilities
704fee23f9Smrg    *
71*b1e83836Smrg    *  Function objects, or _functors_, are objects with an `operator()`
724fee23f9Smrg    *  defined and accessible.  They can be passed as arguments to algorithm
734fee23f9Smrg    *  templates and used in place of a function pointer.  Not only is the
744fee23f9Smrg    *  resulting expressiveness of the library increased, but the generated
754fee23f9Smrg    *  code can be more efficient than what you might write by hand.  When we
76*b1e83836Smrg    *  refer to _functors_, then, generally we include function pointers in
774fee23f9Smrg    *  the description as well.
784fee23f9Smrg    *
794fee23f9Smrg    *  Often, functors are only created as temporaries passed to algorithm
804fee23f9Smrg    *  calls, rather than being created as named variables.
814fee23f9Smrg    *
824fee23f9Smrg    *  Two examples taken from the standard itself follow.  To perform a
83*b1e83836Smrg    *  by-element addition of two vectors `a` and `b` containing `double`,
84*b1e83836Smrg    *  and put the result in `a`, use
854fee23f9Smrg    *  \code
864fee23f9Smrg    *  transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
874fee23f9Smrg    *  \endcode
88*b1e83836Smrg    *  To negate every element in `a`, use
894fee23f9Smrg    *  \code
904fee23f9Smrg    *  transform(a.begin(), a.end(), a.begin(), negate<double>());
914fee23f9Smrg    *  \endcode
92*b1e83836Smrg    *  The addition and negation functions will usually be inlined directly.
934fee23f9Smrg    *
94*b1e83836Smrg    *  An _adaptable function object_ is one which provides nested typedefs
95*b1e83836Smrg    *  `result_type` and either `argument_type` (for a unary function) or
96*b1e83836Smrg    *  `first_argument_type` and `second_argument_type` (for a binary function).
97*b1e83836Smrg    *  Those typedefs are used by function object adaptors such as `bind2nd`.
98*b1e83836Smrg    *  The standard library provides two class templates, `unary_function` and
99*b1e83836Smrg    *  `binary_function`, which define those typedefs and so can be used as
100*b1e83836Smrg    *  base classes of adaptable function objects.
101*b1e83836Smrg    *
102*b1e83836Smrg    *  Since C++11 the use of function object adaptors has been superseded by
103*b1e83836Smrg    *  more powerful tools such as lambda expressions, `function<>`, and more
104*b1e83836Smrg    *  powerful type deduction (using `auto` and `decltype`). The helpers for
105*b1e83836Smrg    *  defining adaptable function objects are deprecated since C++11, and no
106*b1e83836Smrg    *  longer part of the standard library since C++17. However, they are still
107*b1e83836Smrg    *  defined and used by libstdc++ after C++17, as a conforming extension.
1084fee23f9Smrg    *
1094fee23f9Smrg    *  @{
1104fee23f9Smrg    */
111*b1e83836Smrg 
1124fee23f9Smrg   /**
113*b1e83836Smrg    *  Helper for defining adaptable unary function objects.
114*b1e83836Smrg    *  @deprecated Deprecated in C++11, no longer in the standard since C++17.
1154fee23f9Smrg    */
1164fee23f9Smrg   template<typename _Arg, typename _Result>
1174fee23f9Smrg     struct unary_function
1184fee23f9Smrg     {
11948fb7bfaSmrg       /// @c argument_type is the type of the argument
12048fb7bfaSmrg       typedef _Arg 	argument_type;
1214fee23f9Smrg 
12248fb7bfaSmrg       /// @c result_type is the return type
12348fb7bfaSmrg       typedef _Result 	result_type;
124*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
1254fee23f9Smrg 
1264fee23f9Smrg   /**
127*b1e83836Smrg    *  Helper for defining adaptable binary function objects.
128*b1e83836Smrg    *  @deprecated Deprecated in C++11, no longer in the standard since C++17.
1294fee23f9Smrg    */
1304fee23f9Smrg   template<typename _Arg1, typename _Arg2, typename _Result>
1314fee23f9Smrg     struct binary_function
1324fee23f9Smrg     {
13348fb7bfaSmrg       /// @c first_argument_type is the type of the first argument
13448fb7bfaSmrg       typedef _Arg1 	first_argument_type;
1354fee23f9Smrg 
13648fb7bfaSmrg       /// @c second_argument_type is the type of the second argument
13748fb7bfaSmrg       typedef _Arg2 	second_argument_type;
13848fb7bfaSmrg 
13948fb7bfaSmrg       /// @c result_type is the return type
14048fb7bfaSmrg       typedef _Result 	result_type;
141*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
1424fee23f9Smrg   /** @}  */
1434fee23f9Smrg 
1444fee23f9Smrg   // 20.3.2 arithmetic
145*b1e83836Smrg 
146*b1e83836Smrg   /** @defgroup arithmetic_functors Arithmetic Function Object Classes
1474fee23f9Smrg    *  @ingroup functors
1484fee23f9Smrg    *
149*b1e83836Smrg    *  The library provides function objects for basic arithmetic operations.
150*b1e83836Smrg    *  See the documentation for @link functors function objects @endlink
1514fee23f9Smrg    *  for examples of their use.
1524fee23f9Smrg    *
1534fee23f9Smrg    *  @{
1544fee23f9Smrg    */
1554d5abbe8Smrg 
1564d5abbe8Smrg #if __cplusplus > 201103L
1574d5abbe8Smrg   struct __is_transparent;  // undefined
1584d5abbe8Smrg 
1594d5abbe8Smrg   template<typename _Tp = void>
1604d5abbe8Smrg     struct plus;
1614d5abbe8Smrg 
1624d5abbe8Smrg   template<typename _Tp = void>
1634d5abbe8Smrg     struct minus;
1644d5abbe8Smrg 
1654d5abbe8Smrg   template<typename _Tp = void>
1664d5abbe8Smrg     struct multiplies;
1674d5abbe8Smrg 
1684d5abbe8Smrg   template<typename _Tp = void>
1694d5abbe8Smrg     struct divides;
1704d5abbe8Smrg 
1714d5abbe8Smrg   template<typename _Tp = void>
1724d5abbe8Smrg     struct modulus;
1734d5abbe8Smrg 
1744d5abbe8Smrg   template<typename _Tp = void>
1754d5abbe8Smrg     struct negate;
1764d5abbe8Smrg #endif
1774d5abbe8Smrg 
178*b1e83836Smrg // Ignore warnings about unary_function and binary_function.
179*b1e83836Smrg #pragma GCC diagnostic push
180*b1e83836Smrg #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
181*b1e83836Smrg 
1824fee23f9Smrg   /// One of the @link arithmetic_functors math functors@endlink.
1834fee23f9Smrg   template<typename _Tp>
1844fee23f9Smrg     struct plus : public binary_function<_Tp, _Tp, _Tp>
1854fee23f9Smrg     {
186*b1e83836Smrg       /// Returns the sum
1874d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
1884fee23f9Smrg       _Tp
1894fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
1904fee23f9Smrg       { return __x + __y; }
1914fee23f9Smrg     };
1924fee23f9Smrg 
1934fee23f9Smrg   /// One of the @link arithmetic_functors math functors@endlink.
1944fee23f9Smrg   template<typename _Tp>
1954fee23f9Smrg     struct minus : public binary_function<_Tp, _Tp, _Tp>
1964fee23f9Smrg     {
1974d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
1984fee23f9Smrg       _Tp
1994fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
2004fee23f9Smrg       { return __x - __y; }
2014fee23f9Smrg     };
2024fee23f9Smrg 
2034fee23f9Smrg   /// One of the @link arithmetic_functors math functors@endlink.
2044fee23f9Smrg   template<typename _Tp>
2054fee23f9Smrg     struct multiplies : public binary_function<_Tp, _Tp, _Tp>
2064fee23f9Smrg     {
2074d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
2084fee23f9Smrg       _Tp
2094fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
2104fee23f9Smrg       { return __x * __y; }
2114fee23f9Smrg     };
2124fee23f9Smrg 
2134fee23f9Smrg   /// One of the @link arithmetic_functors math functors@endlink.
2144fee23f9Smrg   template<typename _Tp>
2154fee23f9Smrg     struct divides : public binary_function<_Tp, _Tp, _Tp>
2164fee23f9Smrg     {
2174d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
2184fee23f9Smrg       _Tp
2194fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
2204fee23f9Smrg       { return __x / __y; }
2214fee23f9Smrg     };
2224fee23f9Smrg 
2234fee23f9Smrg   /// One of the @link arithmetic_functors math functors@endlink.
2244fee23f9Smrg   template<typename _Tp>
2254fee23f9Smrg     struct modulus : public binary_function<_Tp, _Tp, _Tp>
2264fee23f9Smrg     {
2274d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
2284fee23f9Smrg       _Tp
2294fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
2304fee23f9Smrg       { return __x % __y; }
2314fee23f9Smrg     };
2324fee23f9Smrg 
2334fee23f9Smrg   /// One of the @link arithmetic_functors math functors@endlink.
2344fee23f9Smrg   template<typename _Tp>
2354fee23f9Smrg     struct negate : public unary_function<_Tp, _Tp>
2364fee23f9Smrg     {
2374d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
2384fee23f9Smrg       _Tp
2394fee23f9Smrg       operator()(const _Tp& __x) const
2404fee23f9Smrg       { return -__x; }
2414fee23f9Smrg     };
242*b1e83836Smrg #pragma GCC diagnostic pop
2434d5abbe8Smrg 
2444d5abbe8Smrg #if __cplusplus > 201103L
2454d5abbe8Smrg 
246*b1e83836Smrg #define __cpp_lib_transparent_operators 201510L
2474d5abbe8Smrg 
2484d5abbe8Smrg   template<>
2494d5abbe8Smrg     struct plus<void>
2504d5abbe8Smrg     {
2514d5abbe8Smrg       template <typename _Tp, typename _Up>
2524d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
2534d5abbe8Smrg 	auto
2544d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
2554d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) + std::forward<_Up>(__u)))
2564d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) + std::forward<_Up>(__u))
2574d5abbe8Smrg 	{ return std::forward<_Tp>(__t) + std::forward<_Up>(__u); }
2584d5abbe8Smrg 
2594d5abbe8Smrg       typedef __is_transparent is_transparent;
2604d5abbe8Smrg     };
2614d5abbe8Smrg 
2624d5abbe8Smrg   /// One of the @link arithmetic_functors math functors@endlink.
2634d5abbe8Smrg   template<>
2644d5abbe8Smrg     struct minus<void>
2654d5abbe8Smrg     {
2664d5abbe8Smrg       template <typename _Tp, typename _Up>
2674d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
2684d5abbe8Smrg 	auto
2694d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
2704d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) - std::forward<_Up>(__u)))
2714d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) - std::forward<_Up>(__u))
2724d5abbe8Smrg 	{ return std::forward<_Tp>(__t) - std::forward<_Up>(__u); }
2734d5abbe8Smrg 
2744d5abbe8Smrg       typedef __is_transparent is_transparent;
2754d5abbe8Smrg     };
2764d5abbe8Smrg 
2774d5abbe8Smrg   /// One of the @link arithmetic_functors math functors@endlink.
2784d5abbe8Smrg   template<>
2794d5abbe8Smrg     struct multiplies<void>
2804d5abbe8Smrg     {
2814d5abbe8Smrg       template <typename _Tp, typename _Up>
2824d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
2834d5abbe8Smrg 	auto
2844d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
2854d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) * std::forward<_Up>(__u)))
2864d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) * std::forward<_Up>(__u))
2874d5abbe8Smrg 	{ return std::forward<_Tp>(__t) * std::forward<_Up>(__u); }
2884d5abbe8Smrg 
2894d5abbe8Smrg       typedef __is_transparent is_transparent;
2904d5abbe8Smrg     };
2914d5abbe8Smrg 
2924d5abbe8Smrg   /// One of the @link arithmetic_functors math functors@endlink.
2934d5abbe8Smrg   template<>
2944d5abbe8Smrg     struct divides<void>
2954d5abbe8Smrg     {
2964d5abbe8Smrg       template <typename _Tp, typename _Up>
2974d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
2984d5abbe8Smrg 	auto
2994d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
3004d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) / std::forward<_Up>(__u)))
3014d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) / std::forward<_Up>(__u))
3024d5abbe8Smrg 	{ return std::forward<_Tp>(__t) / std::forward<_Up>(__u); }
3034d5abbe8Smrg 
3044d5abbe8Smrg       typedef __is_transparent is_transparent;
3054d5abbe8Smrg     };
3064d5abbe8Smrg 
3074d5abbe8Smrg   /// One of the @link arithmetic_functors math functors@endlink.
3084d5abbe8Smrg   template<>
3094d5abbe8Smrg     struct modulus<void>
3104d5abbe8Smrg     {
3114d5abbe8Smrg       template <typename _Tp, typename _Up>
3124d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
3134d5abbe8Smrg 	auto
3144d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
3154d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) % std::forward<_Up>(__u)))
3164d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) % std::forward<_Up>(__u))
3174d5abbe8Smrg 	{ return std::forward<_Tp>(__t) % std::forward<_Up>(__u); }
3184d5abbe8Smrg 
3194d5abbe8Smrg       typedef __is_transparent is_transparent;
3204d5abbe8Smrg     };
3214d5abbe8Smrg 
3224d5abbe8Smrg   /// One of the @link arithmetic_functors math functors@endlink.
3234d5abbe8Smrg   template<>
3244d5abbe8Smrg     struct negate<void>
3254d5abbe8Smrg     {
3264d5abbe8Smrg       template <typename _Tp>
3274d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
3284d5abbe8Smrg 	auto
3294d5abbe8Smrg 	operator()(_Tp&& __t) const
3304d5abbe8Smrg 	noexcept(noexcept(-std::forward<_Tp>(__t)))
3314d5abbe8Smrg 	-> decltype(-std::forward<_Tp>(__t))
3324d5abbe8Smrg 	{ return -std::forward<_Tp>(__t); }
3334d5abbe8Smrg 
3344d5abbe8Smrg       typedef __is_transparent is_transparent;
3354d5abbe8Smrg     };
3364d5abbe8Smrg #endif
3374fee23f9Smrg   /** @}  */
3384fee23f9Smrg 
3394fee23f9Smrg   // 20.3.3 comparisons
3404fee23f9Smrg   /** @defgroup comparison_functors Comparison Classes
3414fee23f9Smrg    *  @ingroup functors
3424fee23f9Smrg    *
3434fee23f9Smrg    *  The library provides six wrapper functors for all the basic comparisons
3444fee23f9Smrg    *  in C++, like @c <.
3454fee23f9Smrg    *
3464fee23f9Smrg    *  @{
3474fee23f9Smrg    */
3484d5abbe8Smrg #if __cplusplus > 201103L
3494d5abbe8Smrg   template<typename _Tp = void>
3504d5abbe8Smrg     struct equal_to;
3514d5abbe8Smrg 
3524d5abbe8Smrg   template<typename _Tp = void>
3534d5abbe8Smrg     struct not_equal_to;
3544d5abbe8Smrg 
3554d5abbe8Smrg   template<typename _Tp = void>
3564d5abbe8Smrg     struct greater;
3574d5abbe8Smrg 
3584d5abbe8Smrg   template<typename _Tp = void>
3594d5abbe8Smrg     struct less;
3604d5abbe8Smrg 
3614d5abbe8Smrg   template<typename _Tp = void>
3624d5abbe8Smrg     struct greater_equal;
3634d5abbe8Smrg 
3644d5abbe8Smrg   template<typename _Tp = void>
3654d5abbe8Smrg     struct less_equal;
3664d5abbe8Smrg #endif
3674d5abbe8Smrg 
368*b1e83836Smrg #pragma GCC diagnostic push
369*b1e83836Smrg #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
370*b1e83836Smrg 
3714fee23f9Smrg   /// One of the @link comparison_functors comparison functors@endlink.
3724fee23f9Smrg   template<typename _Tp>
3734fee23f9Smrg     struct equal_to : public binary_function<_Tp, _Tp, bool>
3744fee23f9Smrg     {
3754d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
3764fee23f9Smrg       bool
3774fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
3784fee23f9Smrg       { return __x == __y; }
3794fee23f9Smrg     };
3804fee23f9Smrg 
3814fee23f9Smrg   /// One of the @link comparison_functors comparison functors@endlink.
3824fee23f9Smrg   template<typename _Tp>
3834fee23f9Smrg     struct not_equal_to : public binary_function<_Tp, _Tp, bool>
3844fee23f9Smrg     {
3854d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
3864fee23f9Smrg       bool
3874fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
3884fee23f9Smrg       { return __x != __y; }
3894fee23f9Smrg     };
3904fee23f9Smrg 
3914fee23f9Smrg   /// One of the @link comparison_functors comparison functors@endlink.
3924fee23f9Smrg   template<typename _Tp>
3934fee23f9Smrg     struct greater : public binary_function<_Tp, _Tp, bool>
3944fee23f9Smrg     {
3954d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
3964fee23f9Smrg       bool
3974fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
3984fee23f9Smrg       { return __x > __y; }
3994fee23f9Smrg     };
4004fee23f9Smrg 
4014fee23f9Smrg   /// One of the @link comparison_functors comparison functors@endlink.
4024fee23f9Smrg   template<typename _Tp>
4034fee23f9Smrg     struct less : public binary_function<_Tp, _Tp, bool>
4044fee23f9Smrg     {
4054d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
4064fee23f9Smrg       bool
4074fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
4084fee23f9Smrg       { return __x < __y; }
4094fee23f9Smrg     };
4104fee23f9Smrg 
4114fee23f9Smrg   /// One of the @link comparison_functors comparison functors@endlink.
4124fee23f9Smrg   template<typename _Tp>
4134fee23f9Smrg     struct greater_equal : public binary_function<_Tp, _Tp, bool>
4144fee23f9Smrg     {
4154d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
4164fee23f9Smrg       bool
4174fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
4184fee23f9Smrg       { return __x >= __y; }
4194fee23f9Smrg     };
4204fee23f9Smrg 
4214fee23f9Smrg   /// One of the @link comparison_functors comparison functors@endlink.
4224fee23f9Smrg   template<typename _Tp>
4234fee23f9Smrg     struct less_equal : public binary_function<_Tp, _Tp, bool>
4244fee23f9Smrg     {
4254d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
4264fee23f9Smrg       bool
4274fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
4284fee23f9Smrg       { return __x <= __y; }
4294fee23f9Smrg     };
4304d5abbe8Smrg 
431a3e9eb18Smrg   // Partial specialization of std::greater for pointers.
432a3e9eb18Smrg   template<typename _Tp>
433a3e9eb18Smrg     struct greater<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
434a3e9eb18Smrg     {
435a3e9eb18Smrg       _GLIBCXX14_CONSTEXPR bool
436a3e9eb18Smrg       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
437a3e9eb18Smrg       {
438181254a7Smrg #if __cplusplus >= 201402L
439*b1e83836Smrg 	if (std::__is_constant_evaluated())
440a3e9eb18Smrg 	  return __x > __y;
441181254a7Smrg #endif
442a3e9eb18Smrg 	return (__UINTPTR_TYPE__)__x > (__UINTPTR_TYPE__)__y;
443a3e9eb18Smrg       }
444a3e9eb18Smrg     };
445a3e9eb18Smrg 
446a3e9eb18Smrg   // Partial specialization of std::less for pointers.
447a3e9eb18Smrg   template<typename _Tp>
448a3e9eb18Smrg     struct less<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
449a3e9eb18Smrg     {
450a3e9eb18Smrg       _GLIBCXX14_CONSTEXPR bool
451a3e9eb18Smrg       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
452a3e9eb18Smrg       {
453181254a7Smrg #if __cplusplus >= 201402L
454*b1e83836Smrg 	if (std::__is_constant_evaluated())
455a3e9eb18Smrg 	  return __x < __y;
456181254a7Smrg #endif
457a3e9eb18Smrg 	return (__UINTPTR_TYPE__)__x < (__UINTPTR_TYPE__)__y;
458a3e9eb18Smrg       }
459a3e9eb18Smrg     };
460a3e9eb18Smrg 
461a3e9eb18Smrg   // Partial specialization of std::greater_equal for pointers.
462a3e9eb18Smrg   template<typename _Tp>
463a3e9eb18Smrg     struct greater_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
464a3e9eb18Smrg     {
465a3e9eb18Smrg       _GLIBCXX14_CONSTEXPR bool
466a3e9eb18Smrg       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
467a3e9eb18Smrg       {
468181254a7Smrg #if __cplusplus >= 201402L
469*b1e83836Smrg 	if (std::__is_constant_evaluated())
470a3e9eb18Smrg 	  return __x >= __y;
471181254a7Smrg #endif
472a3e9eb18Smrg 	return (__UINTPTR_TYPE__)__x >= (__UINTPTR_TYPE__)__y;
473a3e9eb18Smrg       }
474a3e9eb18Smrg     };
475a3e9eb18Smrg 
476a3e9eb18Smrg   // Partial specialization of std::less_equal for pointers.
477a3e9eb18Smrg   template<typename _Tp>
478a3e9eb18Smrg     struct less_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
479a3e9eb18Smrg     {
480a3e9eb18Smrg       _GLIBCXX14_CONSTEXPR bool
481a3e9eb18Smrg       operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
482a3e9eb18Smrg       {
483181254a7Smrg #if __cplusplus >= 201402L
484*b1e83836Smrg 	if (std::__is_constant_evaluated())
485a3e9eb18Smrg 	  return __x <= __y;
486181254a7Smrg #endif
487a3e9eb18Smrg 	return (__UINTPTR_TYPE__)__x <= (__UINTPTR_TYPE__)__y;
488a3e9eb18Smrg       }
489a3e9eb18Smrg     };
490*b1e83836Smrg #pragma GCC diagnostic pop
491a3e9eb18Smrg 
492a3e9eb18Smrg #if __cplusplus >= 201402L
4934d5abbe8Smrg   /// One of the @link comparison_functors comparison functors@endlink.
4944d5abbe8Smrg   template<>
4954d5abbe8Smrg     struct equal_to<void>
4964d5abbe8Smrg     {
4974d5abbe8Smrg       template <typename _Tp, typename _Up>
498a3e9eb18Smrg 	constexpr auto
4994d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
5004d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
5014d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u))
5024d5abbe8Smrg 	{ return std::forward<_Tp>(__t) == std::forward<_Up>(__u); }
5034d5abbe8Smrg 
5044d5abbe8Smrg       typedef __is_transparent is_transparent;
5054d5abbe8Smrg     };
5064d5abbe8Smrg 
5074d5abbe8Smrg   /// One of the @link comparison_functors comparison functors@endlink.
5084d5abbe8Smrg   template<>
5094d5abbe8Smrg     struct not_equal_to<void>
5104d5abbe8Smrg     {
5114d5abbe8Smrg       template <typename _Tp, typename _Up>
512a3e9eb18Smrg 	constexpr auto
5134d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
5144d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) != std::forward<_Up>(__u)))
5154d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) != std::forward<_Up>(__u))
5164d5abbe8Smrg 	{ return std::forward<_Tp>(__t) != std::forward<_Up>(__u); }
5174d5abbe8Smrg 
5184d5abbe8Smrg       typedef __is_transparent is_transparent;
5194d5abbe8Smrg     };
5204d5abbe8Smrg 
5214d5abbe8Smrg   /// One of the @link comparison_functors comparison functors@endlink.
5224d5abbe8Smrg   template<>
5234d5abbe8Smrg     struct greater<void>
5244d5abbe8Smrg     {
5254d5abbe8Smrg       template <typename _Tp, typename _Up>
526a3e9eb18Smrg 	constexpr auto
5274d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
5284d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) > std::forward<_Up>(__u)))
5294d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) > std::forward<_Up>(__u))
530a3e9eb18Smrg 	{
531a3e9eb18Smrg 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
532a3e9eb18Smrg 			__ptr_cmp<_Tp, _Up>{});
533a3e9eb18Smrg 	}
534a3e9eb18Smrg 
535a3e9eb18Smrg       template<typename _Tp, typename _Up>
536a3e9eb18Smrg 	constexpr bool
537a3e9eb18Smrg 	operator()(_Tp* __t, _Up* __u) const noexcept
538a3e9eb18Smrg 	{ return greater<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
53914f5a3b0Smrg 
5408b6133e5Smrg       typedef __is_transparent is_transparent;
541a3e9eb18Smrg 
542a3e9eb18Smrg     private:
543a3e9eb18Smrg       template <typename _Tp, typename _Up>
544a3e9eb18Smrg 	static constexpr decltype(auto)
545a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
546a3e9eb18Smrg 	{ return std::forward<_Tp>(__t) > std::forward<_Up>(__u); }
547a3e9eb18Smrg 
548a3e9eb18Smrg       template <typename _Tp, typename _Up>
549a3e9eb18Smrg 	static constexpr bool
550a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
551a3e9eb18Smrg 	{
552a3e9eb18Smrg 	  return greater<const volatile void*>{}(
553a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
554a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
555a3e9eb18Smrg 	}
556a3e9eb18Smrg 
557a3e9eb18Smrg       // True if there is no viable operator> member function.
558a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
559a3e9eb18Smrg 	struct __not_overloaded2 : true_type { };
560a3e9eb18Smrg 
561a3e9eb18Smrg       // False if we can call T.operator>(U)
562a3e9eb18Smrg       template<typename _Tp, typename _Up>
563a3e9eb18Smrg 	struct __not_overloaded2<_Tp, _Up, __void_t<
564a3e9eb18Smrg 	  decltype(std::declval<_Tp>().operator>(std::declval<_Up>()))>>
565a3e9eb18Smrg 	: false_type { };
566a3e9eb18Smrg 
567a3e9eb18Smrg       // True if there is no overloaded operator> for these operands.
568a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
569a3e9eb18Smrg 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
570a3e9eb18Smrg 
571a3e9eb18Smrg       // False if we can call operator>(T,U)
572a3e9eb18Smrg       template<typename _Tp, typename _Up>
573a3e9eb18Smrg 	struct __not_overloaded<_Tp, _Up, __void_t<
574a3e9eb18Smrg 	  decltype(operator>(std::declval<_Tp>(), std::declval<_Up>()))>>
575a3e9eb18Smrg 	: false_type { };
576a3e9eb18Smrg 
577a3e9eb18Smrg       template<typename _Tp, typename _Up>
578a3e9eb18Smrg 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
579a3e9eb18Smrg 	      is_convertible<_Tp, const volatile void*>,
580a3e9eb18Smrg 	      is_convertible<_Up, const volatile void*>>;
5814d5abbe8Smrg     };
5824d5abbe8Smrg 
5834d5abbe8Smrg   /// One of the @link comparison_functors comparison functors@endlink.
5844d5abbe8Smrg   template<>
5854d5abbe8Smrg     struct less<void>
5864d5abbe8Smrg     {
5874d5abbe8Smrg       template <typename _Tp, typename _Up>
588a3e9eb18Smrg 	constexpr auto
5894d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
5904d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) < std::forward<_Up>(__u)))
5914d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) < std::forward<_Up>(__u))
592a3e9eb18Smrg 	{
593a3e9eb18Smrg 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
594a3e9eb18Smrg 			__ptr_cmp<_Tp, _Up>{});
595a3e9eb18Smrg 	}
596a3e9eb18Smrg 
597a3e9eb18Smrg       template<typename _Tp, typename _Up>
598a3e9eb18Smrg 	constexpr bool
599a3e9eb18Smrg 	operator()(_Tp* __t, _Up* __u) const noexcept
600a3e9eb18Smrg 	{ return less<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
60114f5a3b0Smrg 
6028b6133e5Smrg       typedef __is_transparent is_transparent;
603a3e9eb18Smrg 
604a3e9eb18Smrg     private:
605a3e9eb18Smrg       template <typename _Tp, typename _Up>
606a3e9eb18Smrg 	static constexpr decltype(auto)
607a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
608a3e9eb18Smrg 	{ return std::forward<_Tp>(__t) < std::forward<_Up>(__u); }
609a3e9eb18Smrg 
610a3e9eb18Smrg       template <typename _Tp, typename _Up>
611a3e9eb18Smrg 	static constexpr bool
612a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
613a3e9eb18Smrg 	{
614a3e9eb18Smrg 	  return less<const volatile void*>{}(
615a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
616a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
617a3e9eb18Smrg 	}
618a3e9eb18Smrg 
619a3e9eb18Smrg       // True if there is no viable operator< member function.
620a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
621a3e9eb18Smrg 	struct __not_overloaded2 : true_type { };
622a3e9eb18Smrg 
623a3e9eb18Smrg       // False if we can call T.operator<(U)
624a3e9eb18Smrg       template<typename _Tp, typename _Up>
625a3e9eb18Smrg 	struct __not_overloaded2<_Tp, _Up, __void_t<
626a3e9eb18Smrg 	  decltype(std::declval<_Tp>().operator<(std::declval<_Up>()))>>
627a3e9eb18Smrg 	: false_type { };
628a3e9eb18Smrg 
629a3e9eb18Smrg       // True if there is no overloaded operator< for these operands.
630a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
631a3e9eb18Smrg 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
632a3e9eb18Smrg 
633a3e9eb18Smrg       // False if we can call operator<(T,U)
634a3e9eb18Smrg       template<typename _Tp, typename _Up>
635a3e9eb18Smrg 	struct __not_overloaded<_Tp, _Up, __void_t<
636a3e9eb18Smrg 	  decltype(operator<(std::declval<_Tp>(), std::declval<_Up>()))>>
637a3e9eb18Smrg 	: false_type { };
638a3e9eb18Smrg 
639a3e9eb18Smrg       template<typename _Tp, typename _Up>
640a3e9eb18Smrg 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
641a3e9eb18Smrg 	      is_convertible<_Tp, const volatile void*>,
642a3e9eb18Smrg 	      is_convertible<_Up, const volatile void*>>;
6434d5abbe8Smrg     };
6444d5abbe8Smrg 
6454d5abbe8Smrg   /// One of the @link comparison_functors comparison functors@endlink.
6464d5abbe8Smrg   template<>
6474d5abbe8Smrg     struct greater_equal<void>
6484d5abbe8Smrg     {
6494d5abbe8Smrg       template <typename _Tp, typename _Up>
650a3e9eb18Smrg 	constexpr auto
6514d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
6524d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) >= std::forward<_Up>(__u)))
6534d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) >= std::forward<_Up>(__u))
654a3e9eb18Smrg 	{
655a3e9eb18Smrg 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
656a3e9eb18Smrg 			__ptr_cmp<_Tp, _Up>{});
657a3e9eb18Smrg 	}
658a3e9eb18Smrg 
659a3e9eb18Smrg       template<typename _Tp, typename _Up>
660a3e9eb18Smrg 	constexpr bool
661a3e9eb18Smrg 	operator()(_Tp* __t, _Up* __u) const noexcept
662a3e9eb18Smrg 	{ return greater_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
66314f5a3b0Smrg 
6648b6133e5Smrg       typedef __is_transparent is_transparent;
665a3e9eb18Smrg 
666a3e9eb18Smrg     private:
667a3e9eb18Smrg       template <typename _Tp, typename _Up>
668a3e9eb18Smrg 	static constexpr decltype(auto)
669a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
670a3e9eb18Smrg 	{ return std::forward<_Tp>(__t) >= std::forward<_Up>(__u); }
671a3e9eb18Smrg 
672a3e9eb18Smrg       template <typename _Tp, typename _Up>
673a3e9eb18Smrg 	static constexpr bool
674a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
675a3e9eb18Smrg 	{
676a3e9eb18Smrg 	  return greater_equal<const volatile void*>{}(
677a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
678a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
679a3e9eb18Smrg 	}
680a3e9eb18Smrg 
681a3e9eb18Smrg       // True if there is no viable operator>= member function.
682a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
683a3e9eb18Smrg 	struct __not_overloaded2 : true_type { };
684a3e9eb18Smrg 
685a3e9eb18Smrg       // False if we can call T.operator>=(U)
686a3e9eb18Smrg       template<typename _Tp, typename _Up>
687a3e9eb18Smrg 	struct __not_overloaded2<_Tp, _Up, __void_t<
688a3e9eb18Smrg 	  decltype(std::declval<_Tp>().operator>=(std::declval<_Up>()))>>
689a3e9eb18Smrg 	: false_type { };
690a3e9eb18Smrg 
691a3e9eb18Smrg       // True if there is no overloaded operator>= for these operands.
692a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
693a3e9eb18Smrg 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
694a3e9eb18Smrg 
695a3e9eb18Smrg       // False if we can call operator>=(T,U)
696a3e9eb18Smrg       template<typename _Tp, typename _Up>
697a3e9eb18Smrg 	struct __not_overloaded<_Tp, _Up, __void_t<
698a3e9eb18Smrg 	  decltype(operator>=(std::declval<_Tp>(), std::declval<_Up>()))>>
699a3e9eb18Smrg 	: false_type { };
700a3e9eb18Smrg 
701a3e9eb18Smrg       template<typename _Tp, typename _Up>
702a3e9eb18Smrg 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
703a3e9eb18Smrg 	      is_convertible<_Tp, const volatile void*>,
704a3e9eb18Smrg 	      is_convertible<_Up, const volatile void*>>;
7054d5abbe8Smrg     };
7064d5abbe8Smrg 
7074d5abbe8Smrg   /// One of the @link comparison_functors comparison functors@endlink.
7084d5abbe8Smrg   template<>
7094d5abbe8Smrg     struct less_equal<void>
7104d5abbe8Smrg     {
7114d5abbe8Smrg       template <typename _Tp, typename _Up>
712a3e9eb18Smrg 	constexpr auto
7134d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
7144d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) <= std::forward<_Up>(__u)))
7154d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) <= std::forward<_Up>(__u))
716a3e9eb18Smrg 	{
717a3e9eb18Smrg 	  return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
718a3e9eb18Smrg 			__ptr_cmp<_Tp, _Up>{});
719a3e9eb18Smrg 	}
720a3e9eb18Smrg 
721a3e9eb18Smrg       template<typename _Tp, typename _Up>
722a3e9eb18Smrg 	constexpr bool
723a3e9eb18Smrg 	operator()(_Tp* __t, _Up* __u) const noexcept
724a3e9eb18Smrg 	{ return less_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
72514f5a3b0Smrg 
7268b6133e5Smrg       typedef __is_transparent is_transparent;
727a3e9eb18Smrg 
728a3e9eb18Smrg     private:
729a3e9eb18Smrg       template <typename _Tp, typename _Up>
730a3e9eb18Smrg 	static constexpr decltype(auto)
731a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, false_type)
732a3e9eb18Smrg 	{ return std::forward<_Tp>(__t) <= std::forward<_Up>(__u); }
733a3e9eb18Smrg 
734a3e9eb18Smrg       template <typename _Tp, typename _Up>
735a3e9eb18Smrg 	static constexpr bool
736a3e9eb18Smrg 	_S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
737a3e9eb18Smrg 	{
738a3e9eb18Smrg 	  return less_equal<const volatile void*>{}(
739a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Tp>(__t)),
740a3e9eb18Smrg 	      static_cast<const volatile void*>(std::forward<_Up>(__u)));
741a3e9eb18Smrg 	}
742a3e9eb18Smrg 
743a3e9eb18Smrg       // True if there is no viable operator<= member function.
744a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
745a3e9eb18Smrg 	struct __not_overloaded2 : true_type { };
746a3e9eb18Smrg 
747a3e9eb18Smrg       // False if we can call T.operator<=(U)
748a3e9eb18Smrg       template<typename _Tp, typename _Up>
749a3e9eb18Smrg 	struct __not_overloaded2<_Tp, _Up, __void_t<
750a3e9eb18Smrg 	  decltype(std::declval<_Tp>().operator<=(std::declval<_Up>()))>>
751a3e9eb18Smrg 	: false_type { };
752a3e9eb18Smrg 
753a3e9eb18Smrg       // True if there is no overloaded operator<= for these operands.
754a3e9eb18Smrg       template<typename _Tp, typename _Up, typename = void>
755a3e9eb18Smrg 	struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
756a3e9eb18Smrg 
757a3e9eb18Smrg       // False if we can call operator<=(T,U)
758a3e9eb18Smrg       template<typename _Tp, typename _Up>
759a3e9eb18Smrg 	struct __not_overloaded<_Tp, _Up, __void_t<
760a3e9eb18Smrg 	  decltype(operator<=(std::declval<_Tp>(), std::declval<_Up>()))>>
761a3e9eb18Smrg 	: false_type { };
762a3e9eb18Smrg 
763a3e9eb18Smrg       template<typename _Tp, typename _Up>
764a3e9eb18Smrg 	using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
765a3e9eb18Smrg 	      is_convertible<_Tp, const volatile void*>,
766a3e9eb18Smrg 	      is_convertible<_Up, const volatile void*>>;
7674d5abbe8Smrg     };
768a3e9eb18Smrg #endif // C++14
7694fee23f9Smrg   /** @}  */
7704fee23f9Smrg 
7714fee23f9Smrg   // 20.3.4 logical operations
7724fee23f9Smrg   /** @defgroup logical_functors Boolean Operations Classes
7734fee23f9Smrg    *  @ingroup functors
7744fee23f9Smrg    *
775*b1e83836Smrg    *  The library provides function objects for the logical operations:
776*b1e83836Smrg    *  `&&`, `||`, and `!`.
7774fee23f9Smrg    *
7784fee23f9Smrg    *  @{
7794fee23f9Smrg    */
7804d5abbe8Smrg #if __cplusplus > 201103L
7814d5abbe8Smrg   template<typename _Tp = void>
7824d5abbe8Smrg     struct logical_and;
7834d5abbe8Smrg 
7844d5abbe8Smrg   template<typename _Tp = void>
7854d5abbe8Smrg     struct logical_or;
7864d5abbe8Smrg 
7874d5abbe8Smrg   template<typename _Tp = void>
7884d5abbe8Smrg     struct logical_not;
7894d5abbe8Smrg #endif
7904d5abbe8Smrg 
791*b1e83836Smrg #pragma GCC diagnostic push
792*b1e83836Smrg #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
793*b1e83836Smrg 
7944fee23f9Smrg   /// One of the @link logical_functors Boolean operations functors@endlink.
7954fee23f9Smrg   template<typename _Tp>
7964fee23f9Smrg     struct logical_and : public binary_function<_Tp, _Tp, bool>
7974fee23f9Smrg     {
7984d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
7994fee23f9Smrg       bool
8004fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
8014fee23f9Smrg       { return __x && __y; }
8024fee23f9Smrg     };
8034fee23f9Smrg 
8044fee23f9Smrg   /// One of the @link logical_functors Boolean operations functors@endlink.
8054fee23f9Smrg   template<typename _Tp>
8064fee23f9Smrg     struct logical_or : public binary_function<_Tp, _Tp, bool>
8074fee23f9Smrg     {
8084d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
8094fee23f9Smrg       bool
8104fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
8114fee23f9Smrg       { return __x || __y; }
8124fee23f9Smrg     };
8134fee23f9Smrg 
8144fee23f9Smrg   /// One of the @link logical_functors Boolean operations functors@endlink.
8154fee23f9Smrg   template<typename _Tp>
8164fee23f9Smrg     struct logical_not : public unary_function<_Tp, bool>
8174fee23f9Smrg     {
8184d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
8194fee23f9Smrg       bool
8204fee23f9Smrg       operator()(const _Tp& __x) const
8214fee23f9Smrg       { return !__x; }
8224fee23f9Smrg     };
823*b1e83836Smrg #pragma GCC diagnostic pop
8244d5abbe8Smrg 
8254d5abbe8Smrg #if __cplusplus > 201103L
8264d5abbe8Smrg   /// One of the @link logical_functors Boolean operations functors@endlink.
8274d5abbe8Smrg   template<>
8284d5abbe8Smrg     struct logical_and<void>
8294d5abbe8Smrg     {
8304d5abbe8Smrg       template <typename _Tp, typename _Up>
8314d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
8324d5abbe8Smrg 	auto
8334d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
8344d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) && std::forward<_Up>(__u)))
8354d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) && std::forward<_Up>(__u))
8364d5abbe8Smrg 	{ return std::forward<_Tp>(__t) && std::forward<_Up>(__u); }
8374d5abbe8Smrg 
8384d5abbe8Smrg       typedef __is_transparent is_transparent;
8394d5abbe8Smrg     };
8404d5abbe8Smrg 
8414d5abbe8Smrg   /// One of the @link logical_functors Boolean operations functors@endlink.
8424d5abbe8Smrg   template<>
8434d5abbe8Smrg     struct logical_or<void>
8444d5abbe8Smrg     {
8454d5abbe8Smrg       template <typename _Tp, typename _Up>
8464d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
8474d5abbe8Smrg 	auto
8484d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
8494d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) || std::forward<_Up>(__u)))
8504d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) || std::forward<_Up>(__u))
8514d5abbe8Smrg 	{ return std::forward<_Tp>(__t) || std::forward<_Up>(__u); }
8524d5abbe8Smrg 
8534d5abbe8Smrg       typedef __is_transparent is_transparent;
8544d5abbe8Smrg     };
8554d5abbe8Smrg 
8564d5abbe8Smrg   /// One of the @link logical_functors Boolean operations functors@endlink.
8574d5abbe8Smrg   template<>
8584d5abbe8Smrg     struct logical_not<void>
8594d5abbe8Smrg     {
8604d5abbe8Smrg       template <typename _Tp>
8614d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
8624d5abbe8Smrg 	auto
8634d5abbe8Smrg 	operator()(_Tp&& __t) const
8644d5abbe8Smrg 	noexcept(noexcept(!std::forward<_Tp>(__t)))
8654d5abbe8Smrg 	-> decltype(!std::forward<_Tp>(__t))
8664d5abbe8Smrg 	{ return !std::forward<_Tp>(__t); }
8674d5abbe8Smrg 
8684d5abbe8Smrg       typedef __is_transparent is_transparent;
8694d5abbe8Smrg     };
8704d5abbe8Smrg #endif
8714fee23f9Smrg   /** @}  */
8724fee23f9Smrg 
8734d5abbe8Smrg #if __cplusplus > 201103L
8744d5abbe8Smrg   template<typename _Tp = void>
8754d5abbe8Smrg     struct bit_and;
8764d5abbe8Smrg 
8774d5abbe8Smrg   template<typename _Tp = void>
8784d5abbe8Smrg     struct bit_or;
8794d5abbe8Smrg 
8804d5abbe8Smrg   template<typename _Tp = void>
8814d5abbe8Smrg     struct bit_xor;
8824d5abbe8Smrg 
8834d5abbe8Smrg   template<typename _Tp = void>
8844d5abbe8Smrg     struct bit_not;
8854d5abbe8Smrg #endif
8864d5abbe8Smrg 
887*b1e83836Smrg #pragma GCC diagnostic push
888*b1e83836Smrg #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
889*b1e83836Smrg 
8904fee23f9Smrg   // _GLIBCXX_RESOLVE_LIB_DEFECTS
8914fee23f9Smrg   // DR 660. Missing Bitwise Operations.
8924fee23f9Smrg   template<typename _Tp>
8934fee23f9Smrg     struct bit_and : public binary_function<_Tp, _Tp, _Tp>
8944fee23f9Smrg     {
8954d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
8964fee23f9Smrg       _Tp
8974fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
8984fee23f9Smrg       { return __x & __y; }
8994fee23f9Smrg     };
9004fee23f9Smrg 
9014fee23f9Smrg   template<typename _Tp>
9024fee23f9Smrg     struct bit_or : public binary_function<_Tp, _Tp, _Tp>
9034fee23f9Smrg     {
9044d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
9054fee23f9Smrg       _Tp
9064fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
9074fee23f9Smrg       { return __x | __y; }
9084fee23f9Smrg     };
9094fee23f9Smrg 
9104fee23f9Smrg   template<typename _Tp>
9114fee23f9Smrg     struct bit_xor : public binary_function<_Tp, _Tp, _Tp>
9124fee23f9Smrg     {
9134d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
9144fee23f9Smrg       _Tp
9154fee23f9Smrg       operator()(const _Tp& __x, const _Tp& __y) const
9164fee23f9Smrg       { return __x ^ __y; }
9174fee23f9Smrg     };
9184fee23f9Smrg 
9194d5abbe8Smrg   template<typename _Tp>
9204d5abbe8Smrg     struct bit_not : public unary_function<_Tp, _Tp>
9214d5abbe8Smrg     {
9224d5abbe8Smrg     _GLIBCXX14_CONSTEXPR
9234d5abbe8Smrg       _Tp
9244d5abbe8Smrg       operator()(const _Tp& __x) const
9254d5abbe8Smrg       { return ~__x; }
9264d5abbe8Smrg     };
927*b1e83836Smrg #pragma GCC diagnostic pop
9284d5abbe8Smrg 
9294d5abbe8Smrg #if __cplusplus > 201103L
9304d5abbe8Smrg   template <>
9314d5abbe8Smrg     struct bit_and<void>
9324d5abbe8Smrg     {
9334d5abbe8Smrg       template <typename _Tp, typename _Up>
9344d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
9354d5abbe8Smrg 	auto
9364d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
9374d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) & std::forward<_Up>(__u)))
9384d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) & std::forward<_Up>(__u))
9394d5abbe8Smrg 	{ return std::forward<_Tp>(__t) & std::forward<_Up>(__u); }
9404d5abbe8Smrg 
9414d5abbe8Smrg       typedef __is_transparent is_transparent;
9424d5abbe8Smrg     };
9434d5abbe8Smrg 
9444d5abbe8Smrg   template <>
9454d5abbe8Smrg     struct bit_or<void>
9464d5abbe8Smrg     {
9474d5abbe8Smrg       template <typename _Tp, typename _Up>
9484d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
9494d5abbe8Smrg 	auto
9504d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
9514d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) | std::forward<_Up>(__u)))
9524d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) | std::forward<_Up>(__u))
9534d5abbe8Smrg 	{ return std::forward<_Tp>(__t) | std::forward<_Up>(__u); }
9544d5abbe8Smrg 
9554d5abbe8Smrg       typedef __is_transparent is_transparent;
9564d5abbe8Smrg     };
9574d5abbe8Smrg 
9584d5abbe8Smrg   template <>
9594d5abbe8Smrg     struct bit_xor<void>
9604d5abbe8Smrg     {
9614d5abbe8Smrg       template <typename _Tp, typename _Up>
9624d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
9634d5abbe8Smrg 	auto
9644d5abbe8Smrg 	operator()(_Tp&& __t, _Up&& __u) const
9654d5abbe8Smrg 	noexcept(noexcept(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u)))
9664d5abbe8Smrg 	-> decltype(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u))
9674d5abbe8Smrg 	{ return std::forward<_Tp>(__t) ^ std::forward<_Up>(__u); }
9684d5abbe8Smrg 
9694d5abbe8Smrg       typedef __is_transparent is_transparent;
9704d5abbe8Smrg     };
9714d5abbe8Smrg 
9724d5abbe8Smrg   template <>
9734d5abbe8Smrg     struct bit_not<void>
9744d5abbe8Smrg     {
9754d5abbe8Smrg       template <typename _Tp>
9764d5abbe8Smrg 	_GLIBCXX14_CONSTEXPR
9774d5abbe8Smrg 	auto
9784d5abbe8Smrg 	operator()(_Tp&& __t) const
9794d5abbe8Smrg 	noexcept(noexcept(~std::forward<_Tp>(__t)))
9804d5abbe8Smrg 	-> decltype(~std::forward<_Tp>(__t))
9814d5abbe8Smrg 	{ return ~std::forward<_Tp>(__t); }
9824d5abbe8Smrg 
9834d5abbe8Smrg       typedef __is_transparent is_transparent;
9844d5abbe8Smrg     };
985*b1e83836Smrg #endif // C++14
986*b1e83836Smrg 
987*b1e83836Smrg #pragma GCC diagnostic push
988*b1e83836Smrg #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
9894d5abbe8Smrg 
9904fee23f9Smrg   // 20.3.5 negators
9914fee23f9Smrg   /** @defgroup negators Negators
9924fee23f9Smrg    *  @ingroup functors
9934fee23f9Smrg    *
994*b1e83836Smrg    *  The function templates `not1` and `not2` are function object adaptors,
995*b1e83836Smrg    *  which each take a predicate functor and wrap it in an instance of
996*b1e83836Smrg    *  `unary_negate` or `binary_negate`, respectively.  Those classes are
997*b1e83836Smrg    *  functors whose `operator()` evaluates the wrapped predicate function
998*b1e83836Smrg    *  and then returns the negation of the result.
9994fee23f9Smrg    *
10004fee23f9Smrg    *  For example, given a vector of integers and a trivial predicate,
10014fee23f9Smrg    *  \code
10024fee23f9Smrg    *  struct IntGreaterThanThree
10034fee23f9Smrg    *    : public std::unary_function<int, bool>
10044fee23f9Smrg    *  {
1005*b1e83836Smrg    *      bool operator() (int x) const { return x > 3; }
10064fee23f9Smrg    *  };
10074fee23f9Smrg    *
10084fee23f9Smrg    *  std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
10094fee23f9Smrg    *  \endcode
1010*b1e83836Smrg    *  The call to `find_if` will locate the first index (i) of `v` for which
1011*b1e83836Smrg    *  `!(v[i] > 3)` is true.
10124fee23f9Smrg    *
10134fee23f9Smrg    *  The not1/unary_negate combination works on predicates taking a single
1014*b1e83836Smrg    *  argument.  The not2/binary_negate combination works on predicates taking
1015*b1e83836Smrg    *  two arguments.
1016*b1e83836Smrg    *
1017*b1e83836Smrg    *  @deprecated Deprecated in C++17, no longer in the standard since C++20.
1018*b1e83836Smrg    *  Use `not_fn` instead.
10194fee23f9Smrg    *
10204fee23f9Smrg    *  @{
10214fee23f9Smrg    */
10224fee23f9Smrg   /// One of the @link negators negation functors@endlink.
10234fee23f9Smrg   template<typename _Predicate>
1024*b1e83836Smrg     class _GLIBCXX17_DEPRECATED unary_negate
10254fee23f9Smrg     : public unary_function<typename _Predicate::argument_type, bool>
10264fee23f9Smrg     {
10274fee23f9Smrg     protected:
10284fee23f9Smrg       _Predicate _M_pred;
10294fee23f9Smrg 
10304fee23f9Smrg     public:
10314d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
10324fee23f9Smrg       explicit
10334fee23f9Smrg       unary_negate(const _Predicate& __x) : _M_pred(__x) { }
10344fee23f9Smrg 
10354d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
10364fee23f9Smrg       bool
10374fee23f9Smrg       operator()(const typename _Predicate::argument_type& __x) const
10384fee23f9Smrg       { return !_M_pred(__x); }
10394fee23f9Smrg     };
10404fee23f9Smrg 
10414fee23f9Smrg   /// One of the @link negators negation functors@endlink.
10424fee23f9Smrg   template<typename _Predicate>
1043*b1e83836Smrg     _GLIBCXX17_DEPRECATED_SUGGEST("std::not_fn")
10444d5abbe8Smrg     _GLIBCXX14_CONSTEXPR
10454fee23f9Smrg     inline unary_negate<_Predicate>
10464fee23f9Smrg     not1(const _Predicate& __pred)
10474fee23f9Smrg     { return unary_negate<_Predicate>(__pred); }
10484fee23f9Smrg 
10494fee23f9Smrg   /// One of the @link negators negation functors@endlink.
10504fee23f9Smrg   template<typename _Predicate>
1051*b1e83836Smrg     class _GLIBCXX17_DEPRECATED binary_negate
10524fee23f9Smrg     : public binary_function<typename _Predicate::first_argument_type,
10534fee23f9Smrg 			     typename _Predicate::second_argument_type, bool>
10544fee23f9Smrg     {
10554fee23f9Smrg     protected:
10564fee23f9Smrg       _Predicate _M_pred;
10574fee23f9Smrg 
10584fee23f9Smrg     public:
10594d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
10604fee23f9Smrg       explicit
10614fee23f9Smrg       binary_negate(const _Predicate& __x) : _M_pred(__x) { }
10624fee23f9Smrg 
10634d5abbe8Smrg       _GLIBCXX14_CONSTEXPR
10644fee23f9Smrg       bool
10654fee23f9Smrg       operator()(const typename _Predicate::first_argument_type& __x,
10664fee23f9Smrg 		 const typename _Predicate::second_argument_type& __y) const
10674fee23f9Smrg       { return !_M_pred(__x, __y); }
10684fee23f9Smrg     };
10694fee23f9Smrg 
10704fee23f9Smrg   /// One of the @link negators negation functors@endlink.
10714fee23f9Smrg   template<typename _Predicate>
1072*b1e83836Smrg     _GLIBCXX17_DEPRECATED_SUGGEST("std::not_fn")
10734d5abbe8Smrg     _GLIBCXX14_CONSTEXPR
10744fee23f9Smrg     inline binary_negate<_Predicate>
10754fee23f9Smrg     not2(const _Predicate& __pred)
10764fee23f9Smrg     { return binary_negate<_Predicate>(__pred); }
10774fee23f9Smrg   /** @}  */
10784fee23f9Smrg 
10794fee23f9Smrg   // 20.3.7 adaptors pointers functions
10804fee23f9Smrg   /** @defgroup pointer_adaptors Adaptors for pointers to functions
10814fee23f9Smrg    *  @ingroup functors
10824fee23f9Smrg    *
10834fee23f9Smrg    *  The advantage of function objects over pointers to functions is that
10844fee23f9Smrg    *  the objects in the standard library declare nested typedefs describing
1085*b1e83836Smrg    *  their argument and result types with uniform names (e.g., `result_type`
1086*b1e83836Smrg    *  from the base classes `unary_function` and `binary_function`).
10874fee23f9Smrg    *  Sometimes those typedefs are required, not just optional.
10884fee23f9Smrg    *
10894fee23f9Smrg    *  Adaptors are provided to turn pointers to unary (single-argument) and
10904fee23f9Smrg    *  binary (double-argument) functions into function objects.  The
1091*b1e83836Smrg    *  long-winded functor `pointer_to_unary_function` is constructed with a
1092*b1e83836Smrg    *  function pointer `f`, and its `operator()` called with argument `x`
1093*b1e83836Smrg    *  returns `f(x)`.  The functor `pointer_to_binary_function` does the same
1094*b1e83836Smrg    *  thing, but with a double-argument `f` and `operator()`.
10954fee23f9Smrg    *
1096*b1e83836Smrg    *  The function `ptr_fun` takes a pointer-to-function `f` and constructs
10974fee23f9Smrg    *  an instance of the appropriate functor.
10984fee23f9Smrg    *
1099*b1e83836Smrg    *  @deprecated Deprecated in C++11, no longer in the standard since C++17.
1100*b1e83836Smrg    *
11014fee23f9Smrg    *  @{
11024fee23f9Smrg    */
11034fee23f9Smrg   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
11044fee23f9Smrg   template<typename _Arg, typename _Result>
11054fee23f9Smrg     class pointer_to_unary_function : public unary_function<_Arg, _Result>
11064fee23f9Smrg     {
11074fee23f9Smrg     protected:
11084fee23f9Smrg       _Result (*_M_ptr)(_Arg);
11094fee23f9Smrg 
11104fee23f9Smrg     public:
11114fee23f9Smrg       pointer_to_unary_function() { }
11124fee23f9Smrg 
11134fee23f9Smrg       explicit
11144fee23f9Smrg       pointer_to_unary_function(_Result (*__x)(_Arg))
11154fee23f9Smrg       : _M_ptr(__x) { }
11164fee23f9Smrg 
11174fee23f9Smrg       _Result
11184fee23f9Smrg       operator()(_Arg __x) const
11194fee23f9Smrg       { return _M_ptr(__x); }
1120*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
11214fee23f9Smrg 
11224fee23f9Smrg   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
11234fee23f9Smrg   template<typename _Arg, typename _Result>
1124*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::function")
11254fee23f9Smrg     inline pointer_to_unary_function<_Arg, _Result>
11264fee23f9Smrg     ptr_fun(_Result (*__x)(_Arg))
11274fee23f9Smrg     { return pointer_to_unary_function<_Arg, _Result>(__x); }
11284fee23f9Smrg 
11294fee23f9Smrg   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
11304fee23f9Smrg   template<typename _Arg1, typename _Arg2, typename _Result>
11314fee23f9Smrg     class pointer_to_binary_function
11324fee23f9Smrg     : public binary_function<_Arg1, _Arg2, _Result>
11334fee23f9Smrg     {
11344fee23f9Smrg     protected:
11354fee23f9Smrg       _Result (*_M_ptr)(_Arg1, _Arg2);
11364fee23f9Smrg 
11374fee23f9Smrg     public:
11384fee23f9Smrg       pointer_to_binary_function() { }
11394fee23f9Smrg 
11404fee23f9Smrg       explicit
11414fee23f9Smrg       pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
11424fee23f9Smrg       : _M_ptr(__x) { }
11434fee23f9Smrg 
11444fee23f9Smrg       _Result
11454fee23f9Smrg       operator()(_Arg1 __x, _Arg2 __y) const
11464fee23f9Smrg       { return _M_ptr(__x, __y); }
1147*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
11484fee23f9Smrg 
11494fee23f9Smrg   /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
11504fee23f9Smrg   template<typename _Arg1, typename _Arg2, typename _Result>
1151*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::function")
11524fee23f9Smrg     inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
11534fee23f9Smrg     ptr_fun(_Result (*__x)(_Arg1, _Arg2))
11544fee23f9Smrg     { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
11554fee23f9Smrg   /** @}  */
11564fee23f9Smrg 
11574fee23f9Smrg   template<typename _Tp>
115848fb7bfaSmrg     struct _Identity
115948fb7bfaSmrg     : public unary_function<_Tp, _Tp>
11604fee23f9Smrg     {
11614fee23f9Smrg       _Tp&
11624fee23f9Smrg       operator()(_Tp& __x) const
11634fee23f9Smrg       { return __x; }
11644fee23f9Smrg 
11654fee23f9Smrg       const _Tp&
11664fee23f9Smrg       operator()(const _Tp& __x) const
11674fee23f9Smrg       { return __x; }
11684fee23f9Smrg     };
11694fee23f9Smrg 
1170a3e9eb18Smrg   // Partial specialization, avoids confusing errors in e.g. std::set<const T>.
1171a3e9eb18Smrg   template<typename _Tp> struct _Identity<const _Tp> : _Identity<_Tp> { };
1172a3e9eb18Smrg 
11734fee23f9Smrg   template<typename _Pair>
117448fb7bfaSmrg     struct _Select1st
117548fb7bfaSmrg     : public unary_function<_Pair, typename _Pair::first_type>
11764fee23f9Smrg     {
11774fee23f9Smrg       typename _Pair::first_type&
11784fee23f9Smrg       operator()(_Pair& __x) const
11794fee23f9Smrg       { return __x.first; }
11804fee23f9Smrg 
11814fee23f9Smrg       const typename _Pair::first_type&
11824fee23f9Smrg       operator()(const _Pair& __x) const
11834fee23f9Smrg       { return __x.first; }
118448fb7bfaSmrg 
118548fb7bfaSmrg #if __cplusplus >= 201103L
118648fb7bfaSmrg       template<typename _Pair2>
118748fb7bfaSmrg         typename _Pair2::first_type&
118848fb7bfaSmrg         operator()(_Pair2& __x) const
118948fb7bfaSmrg         { return __x.first; }
119048fb7bfaSmrg 
119148fb7bfaSmrg       template<typename _Pair2>
119248fb7bfaSmrg         const typename _Pair2::first_type&
119348fb7bfaSmrg         operator()(const _Pair2& __x) const
119448fb7bfaSmrg         { return __x.first; }
119548fb7bfaSmrg #endif
11964fee23f9Smrg     };
11974fee23f9Smrg 
11984fee23f9Smrg   template<typename _Pair>
119948fb7bfaSmrg     struct _Select2nd
120048fb7bfaSmrg     : public unary_function<_Pair, typename _Pair::second_type>
12014fee23f9Smrg     {
12024fee23f9Smrg       typename _Pair::second_type&
12034fee23f9Smrg       operator()(_Pair& __x) const
12044fee23f9Smrg       { return __x.second; }
12054fee23f9Smrg 
12064fee23f9Smrg       const typename _Pair::second_type&
12074fee23f9Smrg       operator()(const _Pair& __x) const
12084fee23f9Smrg       { return __x.second; }
12094fee23f9Smrg     };
12104fee23f9Smrg 
12114fee23f9Smrg   // 20.3.8 adaptors pointers members
1212*b1e83836Smrg   /** @defgroup ptrmem_adaptors Adaptors for pointers to members
12134fee23f9Smrg    *  @ingroup functors
12144fee23f9Smrg    *
12154fee23f9Smrg    *  There are a total of 8 = 2^3 function objects in this family.
12164fee23f9Smrg    *   (1) Member functions taking no arguments vs member functions taking
12174fee23f9Smrg    *        one argument.
12184fee23f9Smrg    *   (2) Call through pointer vs call through reference.
12194fee23f9Smrg    *   (3) Const vs non-const member function.
12204fee23f9Smrg    *
12214fee23f9Smrg    *  All of this complexity is in the function objects themselves.  You can
1222*b1e83836Smrg    *   ignore it by using the helper function `mem_fun` and `mem_fun_ref`,
12234fee23f9Smrg    *   which create whichever type of adaptor is appropriate.
12244fee23f9Smrg    *
1225*b1e83836Smrg    *  @deprecated Deprecated in C++11, no longer in the standard since C++17.
1226*b1e83836Smrg    *  Use `mem_fn` instead.
1227*b1e83836Smrg    *
12284fee23f9Smrg    *  @{
12294fee23f9Smrg    */
1230*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
12314fee23f9Smrg   template<typename _Ret, typename _Tp>
12324fee23f9Smrg     class mem_fun_t : public unary_function<_Tp*, _Ret>
12334fee23f9Smrg     {
12344fee23f9Smrg     public:
12354fee23f9Smrg       explicit
12364fee23f9Smrg       mem_fun_t(_Ret (_Tp::*__pf)())
12374fee23f9Smrg       : _M_f(__pf) { }
12384fee23f9Smrg 
12394fee23f9Smrg       _Ret
12404fee23f9Smrg       operator()(_Tp* __p) const
12414fee23f9Smrg       { return (__p->*_M_f)(); }
12424fee23f9Smrg 
12434fee23f9Smrg     private:
12444fee23f9Smrg       _Ret (_Tp::*_M_f)();
1245*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
12464fee23f9Smrg 
1247*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
12484fee23f9Smrg   template<typename _Ret, typename _Tp>
12494fee23f9Smrg     class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
12504fee23f9Smrg     {
12514fee23f9Smrg     public:
12524fee23f9Smrg       explicit
12534fee23f9Smrg       const_mem_fun_t(_Ret (_Tp::*__pf)() const)
12544fee23f9Smrg       : _M_f(__pf) { }
12554fee23f9Smrg 
12564fee23f9Smrg       _Ret
12574fee23f9Smrg       operator()(const _Tp* __p) const
12584fee23f9Smrg       { return (__p->*_M_f)(); }
12594fee23f9Smrg 
12604fee23f9Smrg     private:
12614fee23f9Smrg       _Ret (_Tp::*_M_f)() const;
1262*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
12634fee23f9Smrg 
1264*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
12654fee23f9Smrg   template<typename _Ret, typename _Tp>
12664fee23f9Smrg     class mem_fun_ref_t : public unary_function<_Tp, _Ret>
12674fee23f9Smrg     {
12684fee23f9Smrg     public:
12694fee23f9Smrg       explicit
12704fee23f9Smrg       mem_fun_ref_t(_Ret (_Tp::*__pf)())
12714fee23f9Smrg       : _M_f(__pf) { }
12724fee23f9Smrg 
12734fee23f9Smrg       _Ret
12744fee23f9Smrg       operator()(_Tp& __r) const
12754fee23f9Smrg       { return (__r.*_M_f)(); }
12764fee23f9Smrg 
12774fee23f9Smrg     private:
12784fee23f9Smrg       _Ret (_Tp::*_M_f)();
1279*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
12804fee23f9Smrg 
1281*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
12824fee23f9Smrg   template<typename _Ret, typename _Tp>
12834fee23f9Smrg     class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
12844fee23f9Smrg     {
12854fee23f9Smrg     public:
12864fee23f9Smrg       explicit
12874fee23f9Smrg       const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
12884fee23f9Smrg       : _M_f(__pf) { }
12894fee23f9Smrg 
12904fee23f9Smrg       _Ret
12914fee23f9Smrg       operator()(const _Tp& __r) const
12924fee23f9Smrg       { return (__r.*_M_f)(); }
12934fee23f9Smrg 
12944fee23f9Smrg     private:
12954fee23f9Smrg       _Ret (_Tp::*_M_f)() const;
1296*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
12974fee23f9Smrg 
1298*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
12994fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
13004fee23f9Smrg     class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
13014fee23f9Smrg     {
13024fee23f9Smrg     public:
13034fee23f9Smrg       explicit
13044fee23f9Smrg       mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
13054fee23f9Smrg       : _M_f(__pf) { }
13064fee23f9Smrg 
13074fee23f9Smrg       _Ret
13084fee23f9Smrg       operator()(_Tp* __p, _Arg __x) const
13094fee23f9Smrg       { return (__p->*_M_f)(__x); }
13104fee23f9Smrg 
13114fee23f9Smrg     private:
13124fee23f9Smrg       _Ret (_Tp::*_M_f)(_Arg);
1313*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
13144fee23f9Smrg 
1315*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
13164fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
13174fee23f9Smrg     class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
13184fee23f9Smrg     {
13194fee23f9Smrg     public:
13204fee23f9Smrg       explicit
13214fee23f9Smrg       const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
13224fee23f9Smrg       : _M_f(__pf) { }
13234fee23f9Smrg 
13244fee23f9Smrg       _Ret
13254fee23f9Smrg       operator()(const _Tp* __p, _Arg __x) const
13264fee23f9Smrg       { return (__p->*_M_f)(__x); }
13274fee23f9Smrg 
13284fee23f9Smrg     private:
13294fee23f9Smrg       _Ret (_Tp::*_M_f)(_Arg) const;
1330*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
13314fee23f9Smrg 
1332*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
13334fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
13344fee23f9Smrg     class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
13354fee23f9Smrg     {
13364fee23f9Smrg     public:
13374fee23f9Smrg       explicit
13384fee23f9Smrg       mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
13394fee23f9Smrg       : _M_f(__pf) { }
13404fee23f9Smrg 
13414fee23f9Smrg       _Ret
13424fee23f9Smrg       operator()(_Tp& __r, _Arg __x) const
13434fee23f9Smrg       { return (__r.*_M_f)(__x); }
13444fee23f9Smrg 
13454fee23f9Smrg     private:
13464fee23f9Smrg       _Ret (_Tp::*_M_f)(_Arg);
1347*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
13484fee23f9Smrg 
1349*b1e83836Smrg   /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
13504fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
13514fee23f9Smrg     class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
13524fee23f9Smrg     {
13534fee23f9Smrg     public:
13544fee23f9Smrg       explicit
13554fee23f9Smrg       const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
13564fee23f9Smrg       : _M_f(__pf) { }
13574fee23f9Smrg 
13584fee23f9Smrg       _Ret
13594fee23f9Smrg       operator()(const _Tp& __r, _Arg __x) const
13604fee23f9Smrg       { return (__r.*_M_f)(__x); }
13614fee23f9Smrg 
13624fee23f9Smrg     private:
13634fee23f9Smrg       _Ret (_Tp::*_M_f)(_Arg) const;
1364*b1e83836Smrg     } _GLIBCXX11_DEPRECATED;
13654fee23f9Smrg 
13664fee23f9Smrg   // Mem_fun adaptor helper functions.  There are only two:
13674fee23f9Smrg   // mem_fun and mem_fun_ref.
13684fee23f9Smrg   template<typename _Ret, typename _Tp>
1369*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
13704fee23f9Smrg     inline mem_fun_t<_Ret, _Tp>
13714fee23f9Smrg     mem_fun(_Ret (_Tp::*__f)())
13724fee23f9Smrg     { return mem_fun_t<_Ret, _Tp>(__f); }
13734fee23f9Smrg 
13744fee23f9Smrg   template<typename _Ret, typename _Tp>
1375*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
13764fee23f9Smrg     inline const_mem_fun_t<_Ret, _Tp>
13774fee23f9Smrg     mem_fun(_Ret (_Tp::*__f)() const)
13784fee23f9Smrg     { return const_mem_fun_t<_Ret, _Tp>(__f); }
13794fee23f9Smrg 
13804fee23f9Smrg   template<typename _Ret, typename _Tp>
1381*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
13824fee23f9Smrg     inline mem_fun_ref_t<_Ret, _Tp>
13834fee23f9Smrg     mem_fun_ref(_Ret (_Tp::*__f)())
13844fee23f9Smrg     { return mem_fun_ref_t<_Ret, _Tp>(__f); }
13854fee23f9Smrg 
13864fee23f9Smrg   template<typename _Ret, typename _Tp>
1387*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
13884fee23f9Smrg     inline const_mem_fun_ref_t<_Ret, _Tp>
13894fee23f9Smrg     mem_fun_ref(_Ret (_Tp::*__f)() const)
13904fee23f9Smrg     { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
13914fee23f9Smrg 
13924fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
1393*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
13944fee23f9Smrg     inline mem_fun1_t<_Ret, _Tp, _Arg>
13954fee23f9Smrg     mem_fun(_Ret (_Tp::*__f)(_Arg))
13964fee23f9Smrg     { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
13974fee23f9Smrg 
13984fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
1399*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
14004fee23f9Smrg     inline const_mem_fun1_t<_Ret, _Tp, _Arg>
14014fee23f9Smrg     mem_fun(_Ret (_Tp::*__f)(_Arg) const)
14024fee23f9Smrg     { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
14034fee23f9Smrg 
14044fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
1405*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
14064fee23f9Smrg     inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
14074fee23f9Smrg     mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
14084fee23f9Smrg     { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
14094fee23f9Smrg 
14104fee23f9Smrg   template<typename _Ret, typename _Tp, typename _Arg>
1411*b1e83836Smrg     _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
14124fee23f9Smrg     inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
14134fee23f9Smrg     mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
14144fee23f9Smrg     { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
1415*b1e83836Smrg #pragma GCC diagnostic pop
14164fee23f9Smrg 
14174fee23f9Smrg   /** @}  */
14184fee23f9Smrg 
1419*b1e83836Smrg #if __cplusplus >= 201402L
1420*b1e83836Smrg   template<typename _Func, typename _SfinaeType, typename = __void_t<>>
1421*b1e83836Smrg     struct __has_is_transparent
1422*b1e83836Smrg     { };
1423*b1e83836Smrg 
1424*b1e83836Smrg   template<typename _Func, typename _SfinaeType>
1425*b1e83836Smrg     struct __has_is_transparent<_Func, _SfinaeType,
1426*b1e83836Smrg 				__void_t<typename _Func::is_transparent>>
1427*b1e83836Smrg     { typedef void type; };
1428*b1e83836Smrg 
1429*b1e83836Smrg   template<typename _Func, typename _SfinaeType>
1430*b1e83836Smrg     using __has_is_transparent_t
1431*b1e83836Smrg       = typename __has_is_transparent<_Func, _SfinaeType>::type;
1432*b1e83836Smrg #endif
1433*b1e83836Smrg 
143448fb7bfaSmrg _GLIBCXX_END_NAMESPACE_VERSION
143548fb7bfaSmrg } // namespace
14364fee23f9Smrg 
143748fb7bfaSmrg #if (__cplusplus < 201103L) || _GLIBCXX_USE_DEPRECATED
14384fee23f9Smrg # include <backward/binders.h>
14394fee23f9Smrg #endif
14404fee23f9Smrg 
14414fee23f9Smrg #endif /* _STL_FUNCTION_H */
1442