stl_function.h 44 KB

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