libstdc++
stl_function.h
Go to the documentation of this file.
1// Functor implementations -*- C++ -*-
2
3// Copyright (C) 2001-2025 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/*
26 *
27 * Copyright (c) 1994
28 * Hewlett-Packard Company
29 *
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
37 *
38 *
39 * Copyright (c) 1996-1998
40 * Silicon Graphics Computer Systems, Inc.
41 *
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
49 */
50
51/** @file bits/stl_function.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{functional}
54 */
55
56#ifndef _STL_FUNCTION_H
57#define _STL_FUNCTION_H 1
58
59#if __cplusplus > 201103L
60#include <bits/move.h>
61#endif
62
63namespace std _GLIBCXX_VISIBILITY(default)
64{
65_GLIBCXX_BEGIN_NAMESPACE_VERSION
66
67 // 20.3.1 base classes
68 /** @defgroup functors Function Objects
69 * @ingroup utilities
70 *
71 * Function objects, or _functors_, are objects with an `operator()`
72 * defined and accessible. They can be passed as arguments to algorithm
73 * templates and used in place of a function pointer. Not only is the
74 * resulting expressiveness of the library increased, but the generated
75 * code can be more efficient than what you might write by hand. When we
76 * refer to _functors_, then, generally we include function pointers in
77 * the description as well.
78 *
79 * Often, functors are only created as temporaries passed to algorithm
80 * calls, rather than being created as named variables.
81 *
82 * Two examples taken from the standard itself follow. To perform a
83 * by-element addition of two vectors `a` and `b` containing `double`,
84 * and put the result in `a`, use
85 * \code
86 * transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
87 * \endcode
88 * To negate every element in `a`, use
89 * \code
90 * transform(a.begin(), a.end(), a.begin(), negate<double>());
91 * \endcode
92 * The addition and negation functions will usually be inlined directly.
93 *
94 * An _adaptable function object_ is one which provides nested typedefs
95 * `result_type` and either `argument_type` (for a unary function) or
96 * `first_argument_type` and `second_argument_type` (for a binary function).
97 * Those typedefs are used by function object adaptors such as `bind2nd`.
98 * The standard library provides two class templates, `unary_function` and
99 * `binary_function`, which define those typedefs and so can be used as
100 * base classes of adaptable function objects.
101 *
102 * Since C++11 the use of function object adaptors has been superseded by
103 * more powerful tools such as lambda expressions, `function<>`, and more
104 * powerful type deduction (using `auto` and `decltype`). The helpers for
105 * defining adaptable function objects are deprecated since C++11, and no
106 * longer part of the standard library since C++17. However, they are still
107 * defined and used by libstdc++ after C++17, as a conforming extension.
108 *
109 * @{
110 */
111
112 /**
113 * Helper for defining adaptable unary function objects.
114 * @deprecated Deprecated in C++11, no longer in the standard since C++17.
115 */
116 template<typename _Arg, typename _Result>
118 {
119 /// @c argument_type is the type of the argument
120 typedef _Arg argument_type;
121
122 /// @c result_type is the return type
123 typedef _Result result_type;
124 } _GLIBCXX11_DEPRECATED;
125
126 /**
127 * Helper for defining adaptable binary function objects.
128 * @deprecated Deprecated in C++11, no longer in the standard since C++17.
129 */
130 template<typename _Arg1, typename _Arg2, typename _Result>
132 {
133 /// @c first_argument_type is the type of the first argument
134 typedef _Arg1 first_argument_type;
135
136 /// @c second_argument_type is the type of the second argument
137 typedef _Arg2 second_argument_type;
138
139 /// @c result_type is the return type
140 typedef _Result result_type;
141 } _GLIBCXX11_DEPRECATED;
142 /** @} */
143
144 // 20.3.2 arithmetic
145
146 /** @defgroup arithmetic_functors Arithmetic Function Object Classes
147 * @ingroup functors
148 *
149 * The library provides function objects for basic arithmetic operations.
150 * See the documentation for @link functors function objects @endlink
151 * for examples of their use.
152 *
153 * @{
154 */
155
156#if __glibcxx_transparent_operators // C++ >= 14
157 struct __is_transparent; // undefined
158
159 template<typename _Tp = void>
160 struct plus;
161
162 template<typename _Tp = void>
163 struct minus;
164
165 template<typename _Tp = void>
166 struct multiplies;
167
168 template<typename _Tp = void>
169 struct divides;
170
171 template<typename _Tp = void>
172 struct modulus;
173
174 template<typename _Tp = void>
175 struct negate;
176#endif
177
178// Ignore warnings about unary_function and binary_function.
179#pragma GCC diagnostic push
180#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
181
182 /// One of the @link arithmetic_functors math functors@endlink.
183 template<typename _Tp>
184 struct plus : public binary_function<_Tp, _Tp, _Tp>
185 {
186 /// Returns the sum
187 _GLIBCXX14_CONSTEXPR
188 _Tp
189 operator()(const _Tp& __x, const _Tp& __y) const
190 { return __x + __y; }
191 };
192
193 /// One of the @link arithmetic_functors math functors@endlink.
194 template<typename _Tp>
195 struct minus : public binary_function<_Tp, _Tp, _Tp>
196 {
197 _GLIBCXX14_CONSTEXPR
198 _Tp
199 operator()(const _Tp& __x, const _Tp& __y) const
200 { return __x - __y; }
201 };
202
203 /// One of the @link arithmetic_functors math functors@endlink.
204 template<typename _Tp>
205 struct multiplies : public binary_function<_Tp, _Tp, _Tp>
206 {
207 _GLIBCXX14_CONSTEXPR
208 _Tp
209 operator()(const _Tp& __x, const _Tp& __y) const
210 { return __x * __y; }
211 };
212
213 /// One of the @link arithmetic_functors math functors@endlink.
214 template<typename _Tp>
215 struct divides : public binary_function<_Tp, _Tp, _Tp>
216 {
217 _GLIBCXX14_CONSTEXPR
218 _Tp
219 operator()(const _Tp& __x, const _Tp& __y) const
220 { return __x / __y; }
221 };
222
223 /// One of the @link arithmetic_functors math functors@endlink.
224 template<typename _Tp>
225 struct modulus : public binary_function<_Tp, _Tp, _Tp>
226 {
227 _GLIBCXX14_CONSTEXPR
228 _Tp
229 operator()(const _Tp& __x, const _Tp& __y) const
230 { return __x % __y; }
231 };
232
233 /// One of the @link arithmetic_functors math functors@endlink.
234 template<typename _Tp>
235 struct negate : public unary_function<_Tp, _Tp>
236 {
237 _GLIBCXX14_CONSTEXPR
238 _Tp
239 operator()(const _Tp& __x) const
240 { return -__x; }
241 };
242#pragma GCC diagnostic pop
243
244#ifdef __glibcxx_transparent_operators // C++ >= 14
245 template<>
246 struct plus<void>
247 {
248 template <typename _Tp, typename _Up>
249 _GLIBCXX14_CONSTEXPR
250 auto
251 operator()(_Tp&& __t, _Up&& __u) const
252 noexcept(noexcept(std::forward<_Tp>(__t) + std::forward<_Up>(__u)))
253 -> decltype(std::forward<_Tp>(__t) + std::forward<_Up>(__u))
254 { return std::forward<_Tp>(__t) + std::forward<_Up>(__u); }
255
256 typedef __is_transparent is_transparent;
257 };
258
259 /// One of the @link arithmetic_functors math functors@endlink.
260 template<>
261 struct minus<void>
262 {
263 template <typename _Tp, typename _Up>
264 _GLIBCXX14_CONSTEXPR
265 auto
266 operator()(_Tp&& __t, _Up&& __u) const
267 noexcept(noexcept(std::forward<_Tp>(__t) - std::forward<_Up>(__u)))
268 -> decltype(std::forward<_Tp>(__t) - std::forward<_Up>(__u))
269 { return std::forward<_Tp>(__t) - std::forward<_Up>(__u); }
270
271 typedef __is_transparent is_transparent;
272 };
273
274 /// One of the @link arithmetic_functors math functors@endlink.
275 template<>
276 struct multiplies<void>
277 {
278 template <typename _Tp, typename _Up>
279 _GLIBCXX14_CONSTEXPR
280 auto
281 operator()(_Tp&& __t, _Up&& __u) const
282 noexcept(noexcept(std::forward<_Tp>(__t) * std::forward<_Up>(__u)))
283 -> decltype(std::forward<_Tp>(__t) * std::forward<_Up>(__u))
284 { return std::forward<_Tp>(__t) * std::forward<_Up>(__u); }
285
286 typedef __is_transparent is_transparent;
287 };
288
289 /// One of the @link arithmetic_functors math functors@endlink.
290 template<>
291 struct divides<void>
292 {
293 template <typename _Tp, typename _Up>
294 _GLIBCXX14_CONSTEXPR
295 auto
296 operator()(_Tp&& __t, _Up&& __u) const
297 noexcept(noexcept(std::forward<_Tp>(__t) / std::forward<_Up>(__u)))
298 -> decltype(std::forward<_Tp>(__t) / std::forward<_Up>(__u))
299 { return std::forward<_Tp>(__t) / std::forward<_Up>(__u); }
300
301 typedef __is_transparent is_transparent;
302 };
303
304 /// One of the @link arithmetic_functors math functors@endlink.
305 template<>
306 struct modulus<void>
307 {
308 template <typename _Tp, typename _Up>
309 _GLIBCXX14_CONSTEXPR
310 auto
311 operator()(_Tp&& __t, _Up&& __u) const
312 noexcept(noexcept(std::forward<_Tp>(__t) % std::forward<_Up>(__u)))
313 -> decltype(std::forward<_Tp>(__t) % std::forward<_Up>(__u))
314 { return std::forward<_Tp>(__t) % std::forward<_Up>(__u); }
315
316 typedef __is_transparent is_transparent;
317 };
318
319 /// One of the @link arithmetic_functors math functors@endlink.
320 template<>
321 struct negate<void>
322 {
323 template <typename _Tp>
324 _GLIBCXX14_CONSTEXPR
325 auto
326 operator()(_Tp&& __t) const
327 noexcept(noexcept(-std::forward<_Tp>(__t)))
328 -> decltype(-std::forward<_Tp>(__t))
329 { return -std::forward<_Tp>(__t); }
330
331 typedef __is_transparent is_transparent;
332 };
333#endif
334 /** @} */
335
336 // 20.3.3 comparisons
337 /** @defgroup comparison_functors Comparison Classes
338 * @ingroup functors
339 *
340 * The library provides six wrapper functors for all the basic comparisons
341 * in C++, like @c <.
342 *
343 * @{
344 */
345#if __glibcxx_transparent_operators // C++ >= 14
346 template<typename _Tp = void>
347 struct equal_to;
348
349 template<typename _Tp = void>
350 struct not_equal_to;
351
352 template<typename _Tp = void>
353 struct greater;
354
355 template<typename _Tp = void>
356 struct less;
357
358 template<typename _Tp = void>
359 struct greater_equal;
360
361 template<typename _Tp = void>
362 struct less_equal;
363#endif
364
365#pragma GCC diagnostic push
366#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
367
368 /// One of the @link comparison_functors comparison functors@endlink.
369 template<typename _Tp>
370 struct equal_to : public binary_function<_Tp, _Tp, bool>
371 {
372 _GLIBCXX14_CONSTEXPR
373 bool
374 operator()(const _Tp& __x, const _Tp& __y) const
375 { return __x == __y; }
376 };
377
378 /// One of the @link comparison_functors comparison functors@endlink.
379 template<typename _Tp>
380 struct not_equal_to : public binary_function<_Tp, _Tp, bool>
381 {
382 _GLIBCXX14_CONSTEXPR
383 bool
384 operator()(const _Tp& __x, const _Tp& __y) const
385 { return __x != __y; }
386 };
387
388 /// One of the @link comparison_functors comparison functors@endlink.
389 template<typename _Tp>
390 struct greater : public binary_function<_Tp, _Tp, bool>
391 {
392 _GLIBCXX14_CONSTEXPR
393 bool
394 operator()(const _Tp& __x, const _Tp& __y) const
395 { return __x > __y; }
396 };
397
398 /// One of the @link comparison_functors comparison functors@endlink.
399 template<typename _Tp>
400 struct less : public binary_function<_Tp, _Tp, bool>
401 {
402 _GLIBCXX14_CONSTEXPR
403 bool
404 operator()(const _Tp& __x, const _Tp& __y) const
405 { return __x < __y; }
406 };
407
408 /// One of the @link comparison_functors comparison functors@endlink.
409 template<typename _Tp>
410 struct greater_equal : public binary_function<_Tp, _Tp, bool>
411 {
412 _GLIBCXX14_CONSTEXPR
413 bool
414 operator()(const _Tp& __x, const _Tp& __y) const
415 { return __x >= __y; }
416 };
417
418 /// One of the @link comparison_functors comparison functors@endlink.
419 template<typename _Tp>
420 struct less_equal : public binary_function<_Tp, _Tp, bool>
421 {
422 _GLIBCXX14_CONSTEXPR
423 bool
424 operator()(const _Tp& __x, const _Tp& __y) const
425 { return __x <= __y; }
426 };
427
428 // Partial specialization of std::greater for pointers.
429 template<typename _Tp>
430 struct greater<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
431 {
432 _GLIBCXX14_CONSTEXPR bool
433 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
434 {
435#if __cplusplus >= 201402L
436 if (std::__is_constant_evaluated())
437 return __x > __y;
438#endif
439 return (__UINTPTR_TYPE__)__x > (__UINTPTR_TYPE__)__y;
440 }
441 };
442
443 // Partial specialization of std::less for pointers.
444 template<typename _Tp>
445 struct less<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
446 {
447 _GLIBCXX14_CONSTEXPR bool
448 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
449 {
450#if __cplusplus >= 201402L
451 if (std::__is_constant_evaluated())
452 return __x < __y;
453#endif
454 return (__UINTPTR_TYPE__)__x < (__UINTPTR_TYPE__)__y;
455 }
456 };
457
458 // Partial specialization of std::greater_equal for pointers.
459 template<typename _Tp>
461 {
462 _GLIBCXX14_CONSTEXPR bool
463 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
464 {
465#if __cplusplus >= 201402L
466 if (std::__is_constant_evaluated())
467 return __x >= __y;
468#endif
469 return (__UINTPTR_TYPE__)__x >= (__UINTPTR_TYPE__)__y;
470 }
471 };
472
473 // Partial specialization of std::less_equal for pointers.
474 template<typename _Tp>
476 {
477 _GLIBCXX14_CONSTEXPR bool
478 operator()(_Tp* __x, _Tp* __y) const _GLIBCXX_NOTHROW
479 {
480#if __cplusplus >= 201402L
481 if (std::__is_constant_evaluated())
482 return __x <= __y;
483#endif
484 return (__UINTPTR_TYPE__)__x <= (__UINTPTR_TYPE__)__y;
485 }
486 };
487#pragma GCC diagnostic pop
488
489#ifdef __glibcxx_transparent_operators // C++ >= 14
490 /// One of the @link comparison_functors comparison functors@endlink.
491 template<>
492 struct equal_to<void>
493 {
494 template <typename _Tp, typename _Up>
495 constexpr auto
496 operator()(_Tp&& __t, _Up&& __u) const
497 noexcept(noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u)))
498 -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u))
499 { return std::forward<_Tp>(__t) == std::forward<_Up>(__u); }
500
501 typedef __is_transparent is_transparent;
502 };
503
504 /// One of the @link comparison_functors comparison functors@endlink.
505 template<>
506 struct not_equal_to<void>
507 {
508 template <typename _Tp, typename _Up>
509 constexpr auto
510 operator()(_Tp&& __t, _Up&& __u) const
511 noexcept(noexcept(std::forward<_Tp>(__t) != std::forward<_Up>(__u)))
512 -> decltype(std::forward<_Tp>(__t) != std::forward<_Up>(__u))
513 { return std::forward<_Tp>(__t) != std::forward<_Up>(__u); }
514
515 typedef __is_transparent is_transparent;
516 };
517
518 /// One of the @link comparison_functors comparison functors@endlink.
519 template<>
520 struct greater<void>
521 {
522 template <typename _Tp, typename _Up>
523 constexpr auto
524 operator()(_Tp&& __t, _Up&& __u) const
525 noexcept(noexcept(std::forward<_Tp>(__t) > std::forward<_Up>(__u)))
526 -> decltype(std::forward<_Tp>(__t) > std::forward<_Up>(__u))
527 {
528 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
529 __ptr_cmp<_Tp, _Up>{});
530 }
531
532 template<typename _Tp, typename _Up>
533 constexpr bool
534 operator()(_Tp* __t, _Up* __u) const noexcept
535 { return greater<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
536
537 typedef __is_transparent is_transparent;
538
539 private:
540 template <typename _Tp, typename _Up>
541 static constexpr decltype(auto)
542 _S_cmp(_Tp&& __t, _Up&& __u, false_type)
543 { return std::forward<_Tp>(__t) > std::forward<_Up>(__u); }
544
545 template <typename _Tp, typename _Up>
546 static constexpr bool
547 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
548 {
550 static_cast<const volatile void*>(std::forward<_Tp>(__t)),
551 static_cast<const volatile void*>(std::forward<_Up>(__u)));
552 }
553
554 // True if there is no viable operator> member function.
555 template<typename _Tp, typename _Up, typename = void>
556 struct __not_overloaded2 : true_type { };
557
558 // False if we can call T.operator>(U)
559 template<typename _Tp, typename _Up>
560 struct __not_overloaded2<_Tp, _Up, __void_t<
561 decltype(std::declval<_Tp>().operator>(std::declval<_Up>()))>>
562 : false_type { };
563
564 // True if there is no overloaded operator> for these operands.
565 template<typename _Tp, typename _Up, typename = void>
566 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
567
568 // False if we can call operator>(T,U)
569 template<typename _Tp, typename _Up>
570 struct __not_overloaded<_Tp, _Up, __void_t<
571 decltype(operator>(std::declval<_Tp>(), std::declval<_Up>()))>>
572 : false_type { };
573
574 template<typename _Tp, typename _Up>
575 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
576 is_convertible<_Tp, const volatile void*>,
577 is_convertible<_Up, const volatile void*>>;
578 };
579
580 /// One of the @link comparison_functors comparison functors@endlink.
581 template<>
582 struct less<void>
583 {
584 template <typename _Tp, typename _Up>
585 constexpr auto
586 operator()(_Tp&& __t, _Up&& __u) const
587 noexcept(noexcept(std::forward<_Tp>(__t) < std::forward<_Up>(__u)))
588 -> decltype(std::forward<_Tp>(__t) < std::forward<_Up>(__u))
589 {
590 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
591 __ptr_cmp<_Tp, _Up>{});
592 }
593
594 template<typename _Tp, typename _Up>
595 constexpr bool
596 operator()(_Tp* __t, _Up* __u) const noexcept
597 { return less<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
598
599 typedef __is_transparent is_transparent;
600
601 private:
602 template <typename _Tp, typename _Up>
603 static constexpr decltype(auto)
604 _S_cmp(_Tp&& __t, _Up&& __u, false_type)
605 { return std::forward<_Tp>(__t) < std::forward<_Up>(__u); }
606
607 template <typename _Tp, typename _Up>
608 static constexpr bool
609 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
610 {
611 return less<const volatile void*>{}(
612 static_cast<const volatile void*>(std::forward<_Tp>(__t)),
613 static_cast<const volatile void*>(std::forward<_Up>(__u)));
614 }
615
616 // True if there is no viable operator< member function.
617 template<typename _Tp, typename _Up, typename = void>
618 struct __not_overloaded2 : true_type { };
619
620 // False if we can call T.operator<(U)
621 template<typename _Tp, typename _Up>
622 struct __not_overloaded2<_Tp, _Up, __void_t<
623 decltype(std::declval<_Tp>().operator<(std::declval<_Up>()))>>
624 : false_type { };
625
626 // True if there is no overloaded operator< for these operands.
627 template<typename _Tp, typename _Up, typename = void>
628 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
629
630 // False if we can call operator<(T,U)
631 template<typename _Tp, typename _Up>
632 struct __not_overloaded<_Tp, _Up, __void_t<
633 decltype(operator<(std::declval<_Tp>(), std::declval<_Up>()))>>
634 : false_type { };
635
636 template<typename _Tp, typename _Up>
637 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
638 is_convertible<_Tp, const volatile void*>,
639 is_convertible<_Up, const volatile void*>>;
640 };
641
642 /// One of the @link comparison_functors comparison functors@endlink.
643 template<>
644 struct greater_equal<void>
645 {
646 template <typename _Tp, typename _Up>
647 constexpr auto
648 operator()(_Tp&& __t, _Up&& __u) const
649 noexcept(noexcept(std::forward<_Tp>(__t) >= std::forward<_Up>(__u)))
650 -> decltype(std::forward<_Tp>(__t) >= std::forward<_Up>(__u))
651 {
652 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
653 __ptr_cmp<_Tp, _Up>{});
654 }
655
656 template<typename _Tp, typename _Up>
657 constexpr bool
658 operator()(_Tp* __t, _Up* __u) const noexcept
659 { return greater_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
660
661 typedef __is_transparent is_transparent;
662
663 private:
664 template <typename _Tp, typename _Up>
665 static constexpr decltype(auto)
666 _S_cmp(_Tp&& __t, _Up&& __u, false_type)
667 { return std::forward<_Tp>(__t) >= std::forward<_Up>(__u); }
668
669 template <typename _Tp, typename _Up>
670 static constexpr bool
671 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
672 {
674 static_cast<const volatile void*>(std::forward<_Tp>(__t)),
675 static_cast<const volatile void*>(std::forward<_Up>(__u)));
676 }
677
678 // True if there is no viable operator>= member function.
679 template<typename _Tp, typename _Up, typename = void>
680 struct __not_overloaded2 : true_type { };
681
682 // False if we can call T.operator>=(U)
683 template<typename _Tp, typename _Up>
684 struct __not_overloaded2<_Tp, _Up, __void_t<
685 decltype(std::declval<_Tp>().operator>=(std::declval<_Up>()))>>
686 : false_type { };
687
688 // True if there is no overloaded operator>= for these operands.
689 template<typename _Tp, typename _Up, typename = void>
690 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
691
692 // False if we can call operator>=(T,U)
693 template<typename _Tp, typename _Up>
694 struct __not_overloaded<_Tp, _Up, __void_t<
695 decltype(operator>=(std::declval<_Tp>(), std::declval<_Up>()))>>
696 : false_type { };
697
698 template<typename _Tp, typename _Up>
699 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
700 is_convertible<_Tp, const volatile void*>,
701 is_convertible<_Up, const volatile void*>>;
702 };
703
704 /// One of the @link comparison_functors comparison functors@endlink.
705 template<>
706 struct less_equal<void>
707 {
708 template <typename _Tp, typename _Up>
709 constexpr auto
710 operator()(_Tp&& __t, _Up&& __u) const
711 noexcept(noexcept(std::forward<_Tp>(__t) <= std::forward<_Up>(__u)))
712 -> decltype(std::forward<_Tp>(__t) <= std::forward<_Up>(__u))
713 {
714 return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u),
715 __ptr_cmp<_Tp, _Up>{});
716 }
717
718 template<typename _Tp, typename _Up>
719 constexpr bool
720 operator()(_Tp* __t, _Up* __u) const noexcept
721 { return less_equal<common_type_t<_Tp*, _Up*>>{}(__t, __u); }
722
723 typedef __is_transparent is_transparent;
724
725 private:
726 template <typename _Tp, typename _Up>
727 static constexpr decltype(auto)
728 _S_cmp(_Tp&& __t, _Up&& __u, false_type)
729 { return std::forward<_Tp>(__t) <= std::forward<_Up>(__u); }
730
731 template <typename _Tp, typename _Up>
732 static constexpr bool
733 _S_cmp(_Tp&& __t, _Up&& __u, true_type) noexcept
734 {
736 static_cast<const volatile void*>(std::forward<_Tp>(__t)),
737 static_cast<const volatile void*>(std::forward<_Up>(__u)));
738 }
739
740 // True if there is no viable operator<= member function.
741 template<typename _Tp, typename _Up, typename = void>
742 struct __not_overloaded2 : true_type { };
743
744 // False if we can call T.operator<=(U)
745 template<typename _Tp, typename _Up>
746 struct __not_overloaded2<_Tp, _Up, __void_t<
747 decltype(std::declval<_Tp>().operator<=(std::declval<_Up>()))>>
748 : false_type { };
749
750 // True if there is no overloaded operator<= for these operands.
751 template<typename _Tp, typename _Up, typename = void>
752 struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
753
754 // False if we can call operator<=(T,U)
755 template<typename _Tp, typename _Up>
756 struct __not_overloaded<_Tp, _Up, __void_t<
757 decltype(operator<=(std::declval<_Tp>(), std::declval<_Up>()))>>
758 : false_type { };
759
760 template<typename _Tp, typename _Up>
761 using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
762 is_convertible<_Tp, const volatile void*>,
763 is_convertible<_Up, const volatile void*>>;
764 };
765#else // < C++14
766
767 // We need less<void> and equal_to<void> for <bits/predefined_ops.h>
768
769 template<>
770 struct equal_to<void>
771 {
772#ifdef __cpp_rvalue_references
773 template<typename _Tp, typename _Up>
774 bool
775 operator()(_Tp&& __t, _Up&& __u) const
776 { return __t == __u; }
777#else // C++98
778 template<typename _Tp, typename _Up>
779 bool
780 operator()(_Tp& __t, _Up& __u) const { return __t == __u; }
781 template<typename _Tp, typename _Up>
782 bool
783 operator()(const _Tp& __t, _Up& __u) const { return __t == __u; }
784 template<typename _Tp, typename _Up>
785 bool
786 operator()(_Tp& __t, const _Up& __u) const { return __t == __u; }
787 template<typename _Tp, typename _Up>
788 bool
789 operator()(const _Tp& __t, const _Up& __u) const { return __t == __u; }
790#endif
791 };
792
793 template<>
794 struct less<void>
795 {
796#ifdef __cpp_rvalue_references
797 template<typename _Tp, typename _Up>
798 bool
799 operator()(_Tp&& __t, _Up&& __u) const
800 { return __t < __u; }
801#else // C++98
802 template<typename _Tp, typename _Up>
803 bool
804 operator()(_Tp& __t, _Up& __u) const { return __t < __u; }
805 template<typename _Tp, typename _Up>
806 bool
807 operator()(const _Tp& __t, _Up& __u) const { return __t < __u; }
808 template<typename _Tp, typename _Up>
809 bool
810 operator()(_Tp& __t, const _Up& __u) const { return __t < __u; }
811 template<typename _Tp, typename _Up>
812 bool
813 operator()(const _Tp& __t, const _Up& __u) const { return __t < __u; }
814#endif
815 };
816
817#endif // __glibcxx_transparent_operators
818 /** @} */
819
820 // 20.3.4 logical operations
821 /** @defgroup logical_functors Boolean Operations Classes
822 * @ingroup functors
823 *
824 * The library provides function objects for the logical operations:
825 * `&&`, `||`, and `!`.
826 *
827 * @{
828 */
829#ifdef __glibcxx_transparent_operators // C++ >= 14
830 template<typename _Tp = void>
831 struct logical_and;
832
833 template<typename _Tp = void>
834 struct logical_or;
835
836 template<typename _Tp = void>
837 struct logical_not;
838#endif
839
840#pragma GCC diagnostic push
841#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
842
843 /// One of the @link logical_functors Boolean operations functors@endlink.
844 template<typename _Tp>
845 struct logical_and : public binary_function<_Tp, _Tp, bool>
846 {
847 _GLIBCXX14_CONSTEXPR
848 bool
849 operator()(const _Tp& __x, const _Tp& __y) const
850 { return __x && __y; }
851 };
852
853 /// One of the @link logical_functors Boolean operations functors@endlink.
854 template<typename _Tp>
855 struct logical_or : public binary_function<_Tp, _Tp, bool>
856 {
857 _GLIBCXX14_CONSTEXPR
858 bool
859 operator()(const _Tp& __x, const _Tp& __y) const
860 { return __x || __y; }
861 };
862
863 /// One of the @link logical_functors Boolean operations functors@endlink.
864 template<typename _Tp>
865 struct logical_not : public unary_function<_Tp, bool>
866 {
867 _GLIBCXX14_CONSTEXPR
868 bool
869 operator()(const _Tp& __x) const
870 { return !__x; }
871 };
872#pragma GCC diagnostic pop
873
874#ifdef __glibcxx_transparent_operators // C++ >= 14
875 /// One of the @link logical_functors Boolean operations functors@endlink.
876 template<>
877 struct logical_and<void>
878 {
879 template <typename _Tp, typename _Up>
880 _GLIBCXX14_CONSTEXPR
881 auto
882 operator()(_Tp&& __t, _Up&& __u) const
883 noexcept(noexcept(std::forward<_Tp>(__t) && std::forward<_Up>(__u)))
884 -> decltype(std::forward<_Tp>(__t) && std::forward<_Up>(__u))
885 { return std::forward<_Tp>(__t) && std::forward<_Up>(__u); }
886
887 typedef __is_transparent is_transparent;
888 };
889
890 /// One of the @link logical_functors Boolean operations functors@endlink.
891 template<>
892 struct logical_or<void>
893 {
894 template <typename _Tp, typename _Up>
895 _GLIBCXX14_CONSTEXPR
896 auto
897 operator()(_Tp&& __t, _Up&& __u) const
898 noexcept(noexcept(std::forward<_Tp>(__t) || std::forward<_Up>(__u)))
899 -> decltype(std::forward<_Tp>(__t) || std::forward<_Up>(__u))
900 { return std::forward<_Tp>(__t) || std::forward<_Up>(__u); }
901
902 typedef __is_transparent is_transparent;
903 };
904
905 /// One of the @link logical_functors Boolean operations functors@endlink.
906 template<>
907 struct logical_not<void>
908 {
909 template <typename _Tp>
910 _GLIBCXX14_CONSTEXPR
911 auto
912 operator()(_Tp&& __t) const
913 noexcept(noexcept(!std::forward<_Tp>(__t)))
914 -> decltype(!std::forward<_Tp>(__t))
915 { return !std::forward<_Tp>(__t); }
916
917 typedef __is_transparent is_transparent;
918 };
919#endif // __glibcxx_transparent_operators
920 /** @} */
921
922#ifdef __glibcxx_transparent_operators // C++ >= 14
923 template<typename _Tp = void>
924 struct bit_and;
925
926 template<typename _Tp = void>
927 struct bit_or;
928
929 template<typename _Tp = void>
930 struct bit_xor;
931
932 template<typename _Tp = void>
933 struct bit_not;
934#endif
935
936#pragma GCC diagnostic push
937#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
938
939 // _GLIBCXX_RESOLVE_LIB_DEFECTS
940 // DR 660. Missing Bitwise Operations.
941 template<typename _Tp>
942 struct bit_and : public binary_function<_Tp, _Tp, _Tp>
943 {
944 _GLIBCXX14_CONSTEXPR
945 _Tp
946 operator()(const _Tp& __x, const _Tp& __y) const
947 { return __x & __y; }
948 };
949
950 template<typename _Tp>
951 struct bit_or : public binary_function<_Tp, _Tp, _Tp>
952 {
953 _GLIBCXX14_CONSTEXPR
954 _Tp
955 operator()(const _Tp& __x, const _Tp& __y) const
956 { return __x | __y; }
957 };
958
959 template<typename _Tp>
960 struct bit_xor : public binary_function<_Tp, _Tp, _Tp>
961 {
962 _GLIBCXX14_CONSTEXPR
963 _Tp
964 operator()(const _Tp& __x, const _Tp& __y) const
965 { return __x ^ __y; }
966 };
967
968 template<typename _Tp>
969 struct bit_not : public unary_function<_Tp, _Tp>
970 {
971 _GLIBCXX14_CONSTEXPR
972 _Tp
973 operator()(const _Tp& __x) const
974 { return ~__x; }
975 };
976#pragma GCC diagnostic pop
977
978#ifdef __glibcxx_transparent_operators // C++ >= 14
979 template <>
980 struct bit_and<void>
981 {
982 template <typename _Tp, typename _Up>
983 _GLIBCXX14_CONSTEXPR
984 auto
985 operator()(_Tp&& __t, _Up&& __u) const
986 noexcept(noexcept(std::forward<_Tp>(__t) & std::forward<_Up>(__u)))
987 -> decltype(std::forward<_Tp>(__t) & std::forward<_Up>(__u))
988 { return std::forward<_Tp>(__t) & std::forward<_Up>(__u); }
989
990 typedef __is_transparent is_transparent;
991 };
992
993 template <>
994 struct bit_or<void>
995 {
996 template <typename _Tp, typename _Up>
997 _GLIBCXX14_CONSTEXPR
998 auto
999 operator()(_Tp&& __t, _Up&& __u) const
1000 noexcept(noexcept(std::forward<_Tp>(__t) | std::forward<_Up>(__u)))
1001 -> decltype(std::forward<_Tp>(__t) | std::forward<_Up>(__u))
1002 { return std::forward<_Tp>(__t) | std::forward<_Up>(__u); }
1003
1004 typedef __is_transparent is_transparent;
1005 };
1006
1007 template <>
1008 struct bit_xor<void>
1009 {
1010 template <typename _Tp, typename _Up>
1011 _GLIBCXX14_CONSTEXPR
1012 auto
1013 operator()(_Tp&& __t, _Up&& __u) const
1014 noexcept(noexcept(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u)))
1015 -> decltype(std::forward<_Tp>(__t) ^ std::forward<_Up>(__u))
1016 { return std::forward<_Tp>(__t) ^ std::forward<_Up>(__u); }
1017
1018 typedef __is_transparent is_transparent;
1019 };
1020
1021 template <>
1022 struct bit_not<void>
1023 {
1024 template <typename _Tp>
1025 _GLIBCXX14_CONSTEXPR
1026 auto
1027 operator()(_Tp&& __t) const
1028 noexcept(noexcept(~std::forward<_Tp>(__t)))
1029 -> decltype(~std::forward<_Tp>(__t))
1030 { return ~std::forward<_Tp>(__t); }
1031
1032 typedef __is_transparent is_transparent;
1033 };
1034#endif // C++14
1035
1036#pragma GCC diagnostic push
1037#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1038
1039 // 20.3.5 negators
1040 /** @defgroup negators Negators
1041 * @ingroup functors
1042 *
1043 * The function templates `not1` and `not2` are function object adaptors,
1044 * which each take a predicate functor and wrap it in an instance of
1045 * `unary_negate` or `binary_negate`, respectively. Those classes are
1046 * functors whose `operator()` evaluates the wrapped predicate function
1047 * and then returns the negation of the result.
1048 *
1049 * For example, given a vector of integers and a trivial predicate,
1050 * \code
1051 * struct IntGreaterThanThree
1052 * : public std::unary_function<int, bool>
1053 * {
1054 * bool operator() (int x) const { return x > 3; }
1055 * };
1056 *
1057 * std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
1058 * \endcode
1059 * The call to `find_if` will locate the first index (i) of `v` for which
1060 * `!(v[i] > 3)` is true.
1061 *
1062 * The not1/unary_negate combination works on predicates taking a single
1063 * argument. The not2/binary_negate combination works on predicates taking
1064 * two arguments.
1065 *
1066 * @deprecated Deprecated in C++17, no longer in the standard since C++20.
1067 * Use `not_fn` instead.
1068 *
1069 * @{
1070 */
1071 /// One of the @link negators negation functors@endlink.
1072 template<typename _Predicate>
1073 class _GLIBCXX17_DEPRECATED unary_negate
1074 : public unary_function<typename _Predicate::argument_type, bool>
1075 {
1076 protected:
1077 _Predicate _M_pred;
1078
1079 public:
1080 _GLIBCXX14_CONSTEXPR
1081 explicit
1082 unary_negate(const _Predicate& __x) : _M_pred(__x) { }
1083
1084 _GLIBCXX14_CONSTEXPR
1085 bool
1086 operator()(const typename _Predicate::argument_type& __x) const
1087 { return !_M_pred(__x); }
1088 };
1089
1090 /// One of the @link negators negation functors@endlink.
1091 template<typename _Predicate>
1092 _GLIBCXX17_DEPRECATED_SUGGEST("std::not_fn")
1093 _GLIBCXX14_CONSTEXPR
1094 inline unary_negate<_Predicate>
1095 not1(const _Predicate& __pred)
1096 { return unary_negate<_Predicate>(__pred); }
1097
1098 /// One of the @link negators negation functors@endlink.
1099 template<typename _Predicate>
1100 class _GLIBCXX17_DEPRECATED binary_negate
1101 : public binary_function<typename _Predicate::first_argument_type,
1102 typename _Predicate::second_argument_type, bool>
1103 {
1104 protected:
1105 _Predicate _M_pred;
1106
1107 public:
1108 _GLIBCXX14_CONSTEXPR
1109 explicit
1110 binary_negate(const _Predicate& __x) : _M_pred(__x) { }
1111
1112 _GLIBCXX14_CONSTEXPR
1113 bool
1114 operator()(const typename _Predicate::first_argument_type& __x,
1115 const typename _Predicate::second_argument_type& __y) const
1116 { return !_M_pred(__x, __y); }
1117 };
1118
1119 /// One of the @link negators negation functors@endlink.
1120 template<typename _Predicate>
1121 _GLIBCXX17_DEPRECATED_SUGGEST("std::not_fn")
1122 _GLIBCXX14_CONSTEXPR
1123 inline binary_negate<_Predicate>
1124 not2(const _Predicate& __pred)
1125 { return binary_negate<_Predicate>(__pred); }
1126 /** @} */
1127
1128 // 20.3.7 adaptors pointers functions
1129 /** @defgroup pointer_adaptors Adaptors for pointers to functions
1130 * @ingroup functors
1131 *
1132 * The advantage of function objects over pointers to functions is that
1133 * the objects in the standard library declare nested typedefs describing
1134 * their argument and result types with uniform names (e.g., `result_type`
1135 * from the base classes `unary_function` and `binary_function`).
1136 * Sometimes those typedefs are required, not just optional.
1137 *
1138 * Adaptors are provided to turn pointers to unary (single-argument) and
1139 * binary (double-argument) functions into function objects. The
1140 * long-winded functor `pointer_to_unary_function` is constructed with a
1141 * function pointer `f`, and its `operator()` called with argument `x`
1142 * returns `f(x)`. The functor `pointer_to_binary_function` does the same
1143 * thing, but with a double-argument `f` and `operator()`.
1144 *
1145 * The function `ptr_fun` takes a pointer-to-function `f` and constructs
1146 * an instance of the appropriate functor.
1147 *
1148 * @deprecated Deprecated in C++11, no longer in the standard since C++17.
1149 *
1150 * @{
1151 */
1152 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1153 template<typename _Arg, typename _Result>
1154 class pointer_to_unary_function : public unary_function<_Arg, _Result>
1155 {
1156 protected:
1157 _Result (*_M_ptr)(_Arg);
1158
1159 public:
1160 pointer_to_unary_function() { }
1161
1162 explicit
1163 pointer_to_unary_function(_Result (*__x)(_Arg))
1164 : _M_ptr(__x) { }
1165
1166 _Result
1167 operator()(_Arg __x) const
1168 { return _M_ptr(__x); }
1169 } _GLIBCXX11_DEPRECATED;
1170
1171 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1172 template<typename _Arg, typename _Result>
1173 _GLIBCXX11_DEPRECATED_SUGGEST("std::function")
1174 inline pointer_to_unary_function<_Arg, _Result>
1175 ptr_fun(_Result (*__x)(_Arg))
1177
1178 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1179 template<typename _Arg1, typename _Arg2, typename _Result>
1180 class pointer_to_binary_function
1181 : public binary_function<_Arg1, _Arg2, _Result>
1182 {
1183 protected:
1184 _Result (*_M_ptr)(_Arg1, _Arg2);
1185
1186 public:
1187 pointer_to_binary_function() { }
1188
1189 explicit
1190 pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
1191 : _M_ptr(__x) { }
1192
1193 _Result
1194 operator()(_Arg1 __x, _Arg2 __y) const
1195 { return _M_ptr(__x, __y); }
1196 } _GLIBCXX11_DEPRECATED;
1197
1198 /// One of the @link pointer_adaptors adaptors for function pointers@endlink.
1199 template<typename _Arg1, typename _Arg2, typename _Result>
1200 _GLIBCXX11_DEPRECATED_SUGGEST("std::function")
1201 inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
1202 ptr_fun(_Result (*__x)(_Arg1, _Arg2))
1204 /** @} */
1205
1206 template<typename _Tp>
1207 struct _Identity
1208 : public unary_function<_Tp, _Tp>
1209 {
1210 _Tp&
1211 operator()(_Tp& __x) const
1212 { return __x; }
1213
1214 const _Tp&
1215 operator()(const _Tp& __x) const
1216 { return __x; }
1217 };
1218
1219 // Partial specialization, avoids confusing errors in e.g. std::set<const T>.
1220 template<typename _Tp> struct _Identity<const _Tp> : _Identity<_Tp> { };
1221
1222 template<typename _Pair>
1223 struct _Select1st
1224 : public unary_function<_Pair, typename _Pair::first_type>
1225 {
1226 typename _Pair::first_type&
1227 operator()(_Pair& __x) const
1228 { return __x.first; }
1229
1230 const typename _Pair::first_type&
1231 operator()(const _Pair& __x) const
1232 { return __x.first; }
1233
1234#if __cplusplus >= 201103L
1235 template<typename _Pair2>
1236 typename _Pair2::first_type&
1237 operator()(_Pair2& __x) const
1238 { return __x.first; }
1239
1240 template<typename _Pair2>
1241 const typename _Pair2::first_type&
1242 operator()(const _Pair2& __x) const
1243 { return __x.first; }
1244#endif
1245 };
1246
1247 template<typename _Pair>
1248 struct _Select2nd
1249 : public unary_function<_Pair, typename _Pair::second_type>
1250 {
1251 typename _Pair::second_type&
1252 operator()(_Pair& __x) const
1253 { return __x.second; }
1254
1255 const typename _Pair::second_type&
1256 operator()(const _Pair& __x) const
1257 { return __x.second; }
1258 };
1259
1260 // 20.3.8 adaptors pointers members
1261 /** @defgroup ptrmem_adaptors Adaptors for pointers to members
1262 * @ingroup functors
1263 *
1264 * There are a total of 8 = 2^3 function objects in this family.
1265 * (1) Member functions taking no arguments vs member functions taking
1266 * one argument.
1267 * (2) Call through pointer vs call through reference.
1268 * (3) Const vs non-const member function.
1269 *
1270 * All of this complexity is in the function objects themselves. You can
1271 * ignore it by using the helper function `mem_fun` and `mem_fun_ref`,
1272 * which create whichever type of adaptor is appropriate.
1273 *
1274 * @deprecated Deprecated in C++11, no longer in the standard since C++17.
1275 * Use `mem_fn` instead.
1276 *
1277 * @{
1278 */
1279 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1280 template<typename _Ret, typename _Tp>
1281 class mem_fun_t : public unary_function<_Tp*, _Ret>
1282 {
1283 public:
1284 explicit
1285 mem_fun_t(_Ret (_Tp::*__pf)())
1286 : _M_f(__pf) { }
1287
1288 _Ret
1289 operator()(_Tp* __p) const
1290 { return (__p->*_M_f)(); }
1291
1292 private:
1293 _Ret (_Tp::*_M_f)();
1294 } _GLIBCXX11_DEPRECATED;
1295
1296 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1297 template<typename _Ret, typename _Tp>
1298 class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
1299 {
1300 public:
1301 explicit
1302 const_mem_fun_t(_Ret (_Tp::*__pf)() const)
1303 : _M_f(__pf) { }
1304
1305 _Ret
1306 operator()(const _Tp* __p) const
1307 { return (__p->*_M_f)(); }
1308
1309 private:
1310 _Ret (_Tp::*_M_f)() const;
1311 } _GLIBCXX11_DEPRECATED;
1312
1313 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1314 template<typename _Ret, typename _Tp>
1315 class mem_fun_ref_t : public unary_function<_Tp, _Ret>
1316 {
1317 public:
1318 explicit
1319 mem_fun_ref_t(_Ret (_Tp::*__pf)())
1320 : _M_f(__pf) { }
1321
1322 _Ret
1323 operator()(_Tp& __r) const
1324 { return (__r.*_M_f)(); }
1325
1326 private:
1327 _Ret (_Tp::*_M_f)();
1328 } _GLIBCXX11_DEPRECATED;
1329
1330 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1331 template<typename _Ret, typename _Tp>
1332 class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
1333 {
1334 public:
1335 explicit
1336 const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
1337 : _M_f(__pf) { }
1338
1339 _Ret
1340 operator()(const _Tp& __r) const
1341 { return (__r.*_M_f)(); }
1342
1343 private:
1344 _Ret (_Tp::*_M_f)() const;
1345 } _GLIBCXX11_DEPRECATED;
1346
1347 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1348 template<typename _Ret, typename _Tp, typename _Arg>
1349 class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
1350 {
1351 public:
1352 explicit
1353 mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
1354 : _M_f(__pf) { }
1355
1356 _Ret
1357 operator()(_Tp* __p, _Arg __x) const
1358 { return (__p->*_M_f)(__x); }
1359
1360 private:
1361 _Ret (_Tp::*_M_f)(_Arg);
1362 } _GLIBCXX11_DEPRECATED;
1363
1364 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1365 template<typename _Ret, typename _Tp, typename _Arg>
1366 class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
1367 {
1368 public:
1369 explicit
1370 const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
1371 : _M_f(__pf) { }
1372
1373 _Ret
1374 operator()(const _Tp* __p, _Arg __x) const
1375 { return (__p->*_M_f)(__x); }
1376
1377 private:
1378 _Ret (_Tp::*_M_f)(_Arg) const;
1379 } _GLIBCXX11_DEPRECATED;
1380
1381 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1382 template<typename _Ret, typename _Tp, typename _Arg>
1383 class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
1384 {
1385 public:
1386 explicit
1387 mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
1388 : _M_f(__pf) { }
1389
1390 _Ret
1391 operator()(_Tp& __r, _Arg __x) const
1392 { return (__r.*_M_f)(__x); }
1393
1394 private:
1395 _Ret (_Tp::*_M_f)(_Arg);
1396 } _GLIBCXX11_DEPRECATED;
1397
1398 /// One of the @link ptrmem_adaptors adaptors for member pointers@endlink.
1399 template<typename _Ret, typename _Tp, typename _Arg>
1400 class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
1401 {
1402 public:
1403 explicit
1404 const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
1405 : _M_f(__pf) { }
1406
1407 _Ret
1408 operator()(const _Tp& __r, _Arg __x) const
1409 { return (__r.*_M_f)(__x); }
1410
1411 private:
1412 _Ret (_Tp::*_M_f)(_Arg) const;
1413 } _GLIBCXX11_DEPRECATED;
1414
1415 // Mem_fun adaptor helper functions. There are only two:
1416 // mem_fun and mem_fun_ref.
1417 template<typename _Ret, typename _Tp>
1418 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1419 inline mem_fun_t<_Ret, _Tp>
1420 mem_fun(_Ret (_Tp::*__f)())
1421 { return mem_fun_t<_Ret, _Tp>(__f); }
1422
1423 template<typename _Ret, typename _Tp>
1424 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1425 inline const_mem_fun_t<_Ret, _Tp>
1426 mem_fun(_Ret (_Tp::*__f)() const)
1427 { return const_mem_fun_t<_Ret, _Tp>(__f); }
1428
1429 template<typename _Ret, typename _Tp>
1430 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1431 inline mem_fun_ref_t<_Ret, _Tp>
1432 mem_fun_ref(_Ret (_Tp::*__f)())
1433 { return mem_fun_ref_t<_Ret, _Tp>(__f); }
1434
1435 template<typename _Ret, typename _Tp>
1436 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1437 inline const_mem_fun_ref_t<_Ret, _Tp>
1438 mem_fun_ref(_Ret (_Tp::*__f)() const)
1439 { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
1440
1441 template<typename _Ret, typename _Tp, typename _Arg>
1442 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1443 inline mem_fun1_t<_Ret, _Tp, _Arg>
1444 mem_fun(_Ret (_Tp::*__f)(_Arg))
1445 { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
1446
1447 template<typename _Ret, typename _Tp, typename _Arg>
1448 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1449 inline const_mem_fun1_t<_Ret, _Tp, _Arg>
1450 mem_fun(_Ret (_Tp::*__f)(_Arg) const)
1451 { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
1452
1453 template<typename _Ret, typename _Tp, typename _Arg>
1454 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1455 inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
1456 mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
1457 { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
1458
1459 template<typename _Ret, typename _Tp, typename _Arg>
1460 _GLIBCXX11_DEPRECATED_SUGGEST("std::mem_fn")
1461 inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
1462 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
1464#pragma GCC diagnostic pop
1465
1466 /** @} */
1467
1468#ifdef __glibcxx_transparent_operators // C++ >= 14
1469 template<typename _Func, typename _SfinaeType, typename = __void_t<>>
1470 struct __has_is_transparent
1471 { };
1472
1473 template<typename _Func, typename _SfinaeType>
1474 struct __has_is_transparent<_Func, _SfinaeType,
1475 __void_t<typename _Func::is_transparent>>
1476 { typedef void type; };
1477
1478 template<typename _Func, typename _SfinaeType>
1479 using __has_is_transparent_t
1480 = typename __has_is_transparent<_Func, _SfinaeType>::type;
1481
1482#if __cpp_concepts
1483 template<typename _Func>
1484 concept __transparent_comparator
1485 = requires { typename _Func::is_transparent; };
1486#endif
1487#endif
1488
1489_GLIBCXX_END_NAMESPACE_VERSION
1490} // namespace
1491
1492#if (__cplusplus < 201103L) || _GLIBCXX_USE_DEPRECATED
1493# include <backward/binders.h>
1494#endif
1495
1496#endif /* _STL_FUNCTION_H */
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
Definition type_traits:117
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
Definition type_traits:120
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition type_traits:2671
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition move.h:72
constexpr binary_negate< _Predicate > not2(const _Predicate &__pred)
One of the negation functors.
constexpr unary_negate< _Predicate > not1(const _Predicate &__pred)
One of the negation functors.
pointer_to_unary_function< _Arg, _Result > ptr_fun(_Result(*__x)(_Arg))
One of the adaptors for function pointers.
ISO C++ entities toplevel namespace is std.
_Arg argument_type
argument_type is the type of the argument
_Result result_type
result_type is the return type
_Result result_type
result_type is the return type
_Arg2 second_argument_type
second_argument_type is the type of the second argument
_Arg1 first_argument_type
first_argument_type is the type of the first argument
One of the math functors.
constexpr _Tp operator()(const _Tp &__x, const _Tp &__y) const
Returns the sum.
One of the math functors.
One of the math functors.
One of the math functors.
One of the math functors.
One of the math functors.
One of the comparison functors.
One of the comparison functors.
One of the comparison functors.
One of the comparison functors.
One of the comparison functors.
One of the comparison functors.
One of the Boolean operations functors.
One of the Boolean operations functors.
One of the Boolean operations functors.
One of the negation functors.
One of the negation functors.
One of the adaptors for function pointers.
One of the adaptors for function pointers.
One of the adaptors for member pointers.
One of the adaptors for member pointers.
One of the adaptors for member pointers.
One of the adaptors for member pointers.
One of the adaptors for member pointers.
One of the adaptors for member pointers.
One of the adaptors for member pointers.