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