functional 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672
  1. // -*- C++ -*-
  2. //===------------------------ functional ----------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_FUNCTIONAL
  11. #define _LIBCPP_FUNCTIONAL
  12. /*
  13. functional synopsis
  14. namespace std
  15. {
  16. template <class Arg, class Result>
  17. struct unary_function
  18. {
  19. typedef Arg argument_type;
  20. typedef Result result_type;
  21. };
  22. template <class Arg1, class Arg2, class Result>
  23. struct binary_function
  24. {
  25. typedef Arg1 first_argument_type;
  26. typedef Arg2 second_argument_type;
  27. typedef Result result_type;
  28. };
  29. template <class T>
  30. class reference_wrapper
  31. : public unary_function<T1, R> // if wrapping a unary functor
  32. : public binary_function<T1, T2, R> // if wraping a binary functor
  33. {
  34. public:
  35. // types
  36. typedef T type;
  37. typedef see below result_type; // Not always defined
  38. // construct/copy/destroy
  39. reference_wrapper(T&) noexcept;
  40. reference_wrapper(T&&) = delete; // do not bind to temps
  41. reference_wrapper(const reference_wrapper<T>& x) noexcept;
  42. // assignment
  43. reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
  44. // access
  45. operator T& () const noexcept;
  46. T& get() const noexcept;
  47. // invoke
  48. template <class... ArgTypes>
  49. typename result_of<T&(ArgTypes&&...)>::type
  50. operator() (ArgTypes&&...) const;
  51. };
  52. template <class T> reference_wrapper<T> ref(T& t) noexcept;
  53. template <class T> void ref(const T&& t) = delete;
  54. template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
  55. template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
  56. template <class T> void cref(const T&& t) = delete;
  57. template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
  58. template <class T> // <class T=void> in C++14
  59. struct plus : binary_function<T, T, T>
  60. {
  61. T operator()(const T& x, const T& y) const;
  62. };
  63. template <class T> // <class T=void> in C++14
  64. struct minus : binary_function<T, T, T>
  65. {
  66. T operator()(const T& x, const T& y) const;
  67. };
  68. template <class T> // <class T=void> in C++14
  69. struct multiplies : binary_function<T, T, T>
  70. {
  71. T operator()(const T& x, const T& y) const;
  72. };
  73. template <class T> // <class T=void> in C++14
  74. struct divides : binary_function<T, T, T>
  75. {
  76. T operator()(const T& x, const T& y) const;
  77. };
  78. template <class T> // <class T=void> in C++14
  79. struct modulus : binary_function<T, T, T>
  80. {
  81. T operator()(const T& x, const T& y) const;
  82. };
  83. template <class T> // <class T=void> in C++14
  84. struct negate : unary_function<T, T>
  85. {
  86. T operator()(const T& x) const;
  87. };
  88. template <class T> // <class T=void> in C++14
  89. struct equal_to : binary_function<T, T, bool>
  90. {
  91. bool operator()(const T& x, const T& y) const;
  92. };
  93. template <class T> // <class T=void> in C++14
  94. struct not_equal_to : binary_function<T, T, bool>
  95. {
  96. bool operator()(const T& x, const T& y) const;
  97. };
  98. template <class T> // <class T=void> in C++14
  99. struct greater : binary_function<T, T, bool>
  100. {
  101. bool operator()(const T& x, const T& y) const;
  102. };
  103. template <class T> // <class T=void> in C++14
  104. struct less : binary_function<T, T, bool>
  105. {
  106. bool operator()(const T& x, const T& y) const;
  107. };
  108. template <class T> // <class T=void> in C++14
  109. struct greater_equal : binary_function<T, T, bool>
  110. {
  111. bool operator()(const T& x, const T& y) const;
  112. };
  113. template <class T> // <class T=void> in C++14
  114. struct less_equal : binary_function<T, T, bool>
  115. {
  116. bool operator()(const T& x, const T& y) const;
  117. };
  118. template <class T> // <class T=void> in C++14
  119. struct logical_and : binary_function<T, T, bool>
  120. {
  121. bool operator()(const T& x, const T& y) const;
  122. };
  123. template <class T> // <class T=void> in C++14
  124. struct logical_or : binary_function<T, T, bool>
  125. {
  126. bool operator()(const T& x, const T& y) const;
  127. };
  128. template <class T> // <class T=void> in C++14
  129. struct logical_not : unary_function<T, bool>
  130. {
  131. bool operator()(const T& x) const;
  132. };
  133. template <class T> // <class T=void> in C++14
  134. struct bit_and : unary_function<T, bool>
  135. {
  136. bool operator()(const T& x, const T& y) const;
  137. };
  138. template <class T> // <class T=void> in C++14
  139. struct bit_or : unary_function<T, bool>
  140. {
  141. bool operator()(const T& x, const T& y) const;
  142. };
  143. template <class T> // <class T=void> in C++14
  144. struct bit_xor : unary_function<T, bool>
  145. {
  146. bool operator()(const T& x, const T& y) const;
  147. };
  148. template <class T=void> // C++14
  149. struct bit_xor : unary_function<T, bool>
  150. {
  151. bool operator()(const T& x) const;
  152. };
  153. template <class Predicate>
  154. class unary_negate
  155. : public unary_function<typename Predicate::argument_type, bool>
  156. {
  157. public:
  158. explicit unary_negate(const Predicate& pred);
  159. bool operator()(const typename Predicate::argument_type& x) const;
  160. };
  161. template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
  162. template <class Predicate>
  163. class binary_negate
  164. : public binary_function<typename Predicate::first_argument_type,
  165. typename Predicate::second_argument_type,
  166. bool>
  167. {
  168. public:
  169. explicit binary_negate(const Predicate& pred);
  170. bool operator()(const typename Predicate::first_argument_type& x,
  171. const typename Predicate::second_argument_type& y) const;
  172. };
  173. template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
  174. template <class F> unspecified not_fn(F&& f); // C++17
  175. template<class T> struct is_bind_expression;
  176. template<class T> struct is_placeholder;
  177. template<class Fn, class... BoundArgs>
  178. unspecified bind(Fn&&, BoundArgs&&...);
  179. template<class R, class Fn, class... BoundArgs>
  180. unspecified bind(Fn&&, BoundArgs&&...);
  181. namespace placeholders {
  182. // M is the implementation-defined number of placeholders
  183. extern unspecified _1;
  184. extern unspecified _2;
  185. .
  186. .
  187. .
  188. extern unspecified _Mp;
  189. }
  190. template <class Operation>
  191. class binder1st
  192. : public unary_function<typename Operation::second_argument_type,
  193. typename Operation::result_type>
  194. {
  195. protected:
  196. Operation op;
  197. typename Operation::first_argument_type value;
  198. public:
  199. binder1st(const Operation& x, const typename Operation::first_argument_type y);
  200. typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
  201. typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
  202. };
  203. template <class Operation, class T>
  204. binder1st<Operation> bind1st(const Operation& op, const T& x);
  205. template <class Operation>
  206. class binder2nd
  207. : public unary_function<typename Operation::first_argument_type,
  208. typename Operation::result_type>
  209. {
  210. protected:
  211. Operation op;
  212. typename Operation::second_argument_type value;
  213. public:
  214. binder2nd(const Operation& x, const typename Operation::second_argument_type y);
  215. typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
  216. typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
  217. };
  218. template <class Operation, class T>
  219. binder2nd<Operation> bind2nd(const Operation& op, const T& x);
  220. template <class Arg, class Result>
  221. class pointer_to_unary_function : public unary_function<Arg, Result>
  222. {
  223. public:
  224. explicit pointer_to_unary_function(Result (*f)(Arg));
  225. Result operator()(Arg x) const;
  226. };
  227. template <class Arg, class Result>
  228. pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
  229. template <class Arg1, class Arg2, class Result>
  230. class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
  231. {
  232. public:
  233. explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
  234. Result operator()(Arg1 x, Arg2 y) const;
  235. };
  236. template <class Arg1, class Arg2, class Result>
  237. pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
  238. template<class S, class T>
  239. class mem_fun_t : public unary_function<T*, S>
  240. {
  241. public:
  242. explicit mem_fun_t(S (T::*p)());
  243. S operator()(T* p) const;
  244. };
  245. template<class S, class T, class A>
  246. class mem_fun1_t : public binary_function<T*, A, S>
  247. {
  248. public:
  249. explicit mem_fun1_t(S (T::*p)(A));
  250. S operator()(T* p, A x) const;
  251. };
  252. template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
  253. template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
  254. template<class S, class T>
  255. class mem_fun_ref_t : public unary_function<T, S>
  256. {
  257. public:
  258. explicit mem_fun_ref_t(S (T::*p)());
  259. S operator()(T& p) const;
  260. };
  261. template<class S, class T, class A>
  262. class mem_fun1_ref_t : public binary_function<T, A, S>
  263. {
  264. public:
  265. explicit mem_fun1_ref_t(S (T::*p)(A));
  266. S operator()(T& p, A x) const;
  267. };
  268. template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
  269. template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
  270. template <class S, class T>
  271. class const_mem_fun_t : public unary_function<const T*, S>
  272. {
  273. public:
  274. explicit const_mem_fun_t(S (T::*p)() const);
  275. S operator()(const T* p) const;
  276. };
  277. template <class S, class T, class A>
  278. class const_mem_fun1_t : public binary_function<const T*, A, S>
  279. {
  280. public:
  281. explicit const_mem_fun1_t(S (T::*p)(A) const);
  282. S operator()(const T* p, A x) const;
  283. };
  284. template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
  285. template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
  286. template <class S, class T>
  287. class const_mem_fun_ref_t : public unary_function<T, S>
  288. {
  289. public:
  290. explicit const_mem_fun_ref_t(S (T::*p)() const);
  291. S operator()(const T& p) const;
  292. };
  293. template <class S, class T, class A>
  294. class const_mem_fun1_ref_t : public binary_function<T, A, S>
  295. {
  296. public:
  297. explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
  298. S operator()(const T& p, A x) const;
  299. };
  300. template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
  301. template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
  302. template<class R, class T> unspecified mem_fn(R T::*);
  303. class bad_function_call
  304. : public exception
  305. {
  306. };
  307. template<class> class function; // undefined
  308. template<class R, class... ArgTypes>
  309. class function<R(ArgTypes...)>
  310. : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
  311. // ArgTypes contains T1
  312. : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
  313. // ArgTypes contains T1 and T2
  314. {
  315. public:
  316. typedef R result_type;
  317. // construct/copy/destroy:
  318. function() noexcept;
  319. function(nullptr_t) noexcept;
  320. function(const function&);
  321. function(function&&) noexcept;
  322. template<class F>
  323. function(F);
  324. template<Allocator Alloc>
  325. function(allocator_arg_t, const Alloc&) noexcept;
  326. template<Allocator Alloc>
  327. function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
  328. template<Allocator Alloc>
  329. function(allocator_arg_t, const Alloc&, const function&);
  330. template<Allocator Alloc>
  331. function(allocator_arg_t, const Alloc&, function&&);
  332. template<class F, Allocator Alloc>
  333. function(allocator_arg_t, const Alloc&, F);
  334. function& operator=(const function&);
  335. function& operator=(function&&) noexcept;
  336. function& operator=(nullptr_t) noexcept;
  337. template<class F>
  338. function& operator=(F&&);
  339. template<class F>
  340. function& operator=(reference_wrapper<F>) noexcept;
  341. ~function();
  342. // function modifiers:
  343. void swap(function&) noexcept;
  344. template<class F, class Alloc>
  345. void assign(F&&, const Alloc&); // Removed in C++17
  346. // function capacity:
  347. explicit operator bool() const noexcept;
  348. // function invocation:
  349. R operator()(ArgTypes...) const;
  350. // function target access:
  351. const std::type_info& target_type() const noexcept;
  352. template <typename T> T* target() noexcept;
  353. template <typename T> const T* target() const noexcept;
  354. };
  355. // Null pointer comparisons:
  356. template <class R, class ... ArgTypes>
  357. bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
  358. template <class R, class ... ArgTypes>
  359. bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
  360. template <class R, class ... ArgTypes>
  361. bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
  362. template <class R, class ... ArgTypes>
  363. bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
  364. // specialized algorithms:
  365. template <class R, class ... ArgTypes>
  366. void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
  367. template <class T> struct hash;
  368. template <> struct hash<bool>;
  369. template <> struct hash<char>;
  370. template <> struct hash<signed char>;
  371. template <> struct hash<unsigned char>;
  372. template <> struct hash<char16_t>;
  373. template <> struct hash<char32_t>;
  374. template <> struct hash<wchar_t>;
  375. template <> struct hash<short>;
  376. template <> struct hash<unsigned short>;
  377. template <> struct hash<int>;
  378. template <> struct hash<unsigned int>;
  379. template <> struct hash<long>;
  380. template <> struct hash<long long>;
  381. template <> struct hash<unsigned long>;
  382. template <> struct hash<unsigned long long>;
  383. template <> struct hash<float>;
  384. template <> struct hash<double>;
  385. template <> struct hash<long double>;
  386. template<class T> struct hash<T*>;
  387. } // std
  388. POLICY: For non-variadic implementations, the number of arguments is limited
  389. to 3. It is hoped that the need for non-variadic implementations
  390. will be minimal.
  391. */
  392. #include <__config>
  393. #include <type_traits>
  394. #include <typeinfo>
  395. #include <exception>
  396. #include <memory>
  397. #include <tuple>
  398. #include <__functional_base>
  399. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  400. #pragma GCC system_header
  401. #endif
  402. _LIBCPP_BEGIN_NAMESPACE_STD
  403. #if _LIBCPP_STD_VER > 11
  404. template <class _Tp = void>
  405. #else
  406. template <class _Tp>
  407. #endif
  408. struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
  409. {
  410. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  411. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  412. {return __x + __y;}
  413. };
  414. #if _LIBCPP_STD_VER > 11
  415. template <>
  416. struct _LIBCPP_TYPE_VIS_ONLY plus<void>
  417. {
  418. template <class _T1, class _T2>
  419. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  420. auto operator()(_T1&& __t, _T2&& __u) const
  421. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
  422. -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
  423. { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
  424. typedef void is_transparent;
  425. };
  426. #endif
  427. #if _LIBCPP_STD_VER > 11
  428. template <class _Tp = void>
  429. #else
  430. template <class _Tp>
  431. #endif
  432. struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
  433. {
  434. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  435. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  436. {return __x - __y;}
  437. };
  438. #if _LIBCPP_STD_VER > 11
  439. template <>
  440. struct _LIBCPP_TYPE_VIS_ONLY minus<void>
  441. {
  442. template <class _T1, class _T2>
  443. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  444. auto operator()(_T1&& __t, _T2&& __u) const
  445. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
  446. -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
  447. { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
  448. typedef void is_transparent;
  449. };
  450. #endif
  451. #if _LIBCPP_STD_VER > 11
  452. template <class _Tp = void>
  453. #else
  454. template <class _Tp>
  455. #endif
  456. struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
  457. {
  458. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  459. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  460. {return __x * __y;}
  461. };
  462. #if _LIBCPP_STD_VER > 11
  463. template <>
  464. struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
  465. {
  466. template <class _T1, class _T2>
  467. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  468. auto operator()(_T1&& __t, _T2&& __u) const
  469. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
  470. -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
  471. { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
  472. typedef void is_transparent;
  473. };
  474. #endif
  475. #if _LIBCPP_STD_VER > 11
  476. template <class _Tp = void>
  477. #else
  478. template <class _Tp>
  479. #endif
  480. struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
  481. {
  482. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  483. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  484. {return __x / __y;}
  485. };
  486. #if _LIBCPP_STD_VER > 11
  487. template <>
  488. struct _LIBCPP_TYPE_VIS_ONLY divides<void>
  489. {
  490. template <class _T1, class _T2>
  491. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  492. auto operator()(_T1&& __t, _T2&& __u) const
  493. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
  494. -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
  495. { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
  496. typedef void is_transparent;
  497. };
  498. #endif
  499. #if _LIBCPP_STD_VER > 11
  500. template <class _Tp = void>
  501. #else
  502. template <class _Tp>
  503. #endif
  504. struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
  505. {
  506. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  507. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  508. {return __x % __y;}
  509. };
  510. #if _LIBCPP_STD_VER > 11
  511. template <>
  512. struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
  513. {
  514. template <class _T1, class _T2>
  515. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  516. auto operator()(_T1&& __t, _T2&& __u) const
  517. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
  518. -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
  519. { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
  520. typedef void is_transparent;
  521. };
  522. #endif
  523. #if _LIBCPP_STD_VER > 11
  524. template <class _Tp = void>
  525. #else
  526. template <class _Tp>
  527. #endif
  528. struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
  529. {
  530. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  531. _Tp operator()(const _Tp& __x) const
  532. {return -__x;}
  533. };
  534. #if _LIBCPP_STD_VER > 11
  535. template <>
  536. struct _LIBCPP_TYPE_VIS_ONLY negate<void>
  537. {
  538. template <class _Tp>
  539. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  540. auto operator()(_Tp&& __x) const
  541. _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
  542. -> decltype (- _VSTD::forward<_Tp>(__x))
  543. { return - _VSTD::forward<_Tp>(__x); }
  544. typedef void is_transparent;
  545. };
  546. #endif
  547. #if _LIBCPP_STD_VER > 11
  548. template <class _Tp = void>
  549. #else
  550. template <class _Tp>
  551. #endif
  552. struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
  553. {
  554. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  555. bool operator()(const _Tp& __x, const _Tp& __y) const
  556. {return __x == __y;}
  557. };
  558. #if _LIBCPP_STD_VER > 11
  559. template <>
  560. struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
  561. {
  562. template <class _T1, class _T2>
  563. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  564. auto operator()(_T1&& __t, _T2&& __u) const
  565. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
  566. -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
  567. { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
  568. typedef void is_transparent;
  569. };
  570. #endif
  571. #if _LIBCPP_STD_VER > 11
  572. template <class _Tp = void>
  573. #else
  574. template <class _Tp>
  575. #endif
  576. struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
  577. {
  578. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  579. bool operator()(const _Tp& __x, const _Tp& __y) const
  580. {return __x != __y;}
  581. };
  582. #if _LIBCPP_STD_VER > 11
  583. template <>
  584. struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
  585. {
  586. template <class _T1, class _T2>
  587. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  588. auto operator()(_T1&& __t, _T2&& __u) const
  589. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
  590. -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
  591. { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
  592. typedef void is_transparent;
  593. };
  594. #endif
  595. #if _LIBCPP_STD_VER > 11
  596. template <class _Tp = void>
  597. #else
  598. template <class _Tp>
  599. #endif
  600. struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
  601. {
  602. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  603. bool operator()(const _Tp& __x, const _Tp& __y) const
  604. {return __x > __y;}
  605. };
  606. #if _LIBCPP_STD_VER > 11
  607. template <>
  608. struct _LIBCPP_TYPE_VIS_ONLY greater<void>
  609. {
  610. template <class _T1, class _T2>
  611. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  612. auto operator()(_T1&& __t, _T2&& __u) const
  613. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
  614. -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
  615. { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
  616. typedef void is_transparent;
  617. };
  618. #endif
  619. // less in <__functional_base>
  620. #if _LIBCPP_STD_VER > 11
  621. template <class _Tp = void>
  622. #else
  623. template <class _Tp>
  624. #endif
  625. struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
  626. {
  627. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  628. bool operator()(const _Tp& __x, const _Tp& __y) const
  629. {return __x >= __y;}
  630. };
  631. #if _LIBCPP_STD_VER > 11
  632. template <>
  633. struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
  634. {
  635. template <class _T1, class _T2>
  636. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  637. auto operator()(_T1&& __t, _T2&& __u) const
  638. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
  639. -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
  640. { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
  641. typedef void is_transparent;
  642. };
  643. #endif
  644. #if _LIBCPP_STD_VER > 11
  645. template <class _Tp = void>
  646. #else
  647. template <class _Tp>
  648. #endif
  649. struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
  650. {
  651. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  652. bool operator()(const _Tp& __x, const _Tp& __y) const
  653. {return __x <= __y;}
  654. };
  655. #if _LIBCPP_STD_VER > 11
  656. template <>
  657. struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
  658. {
  659. template <class _T1, class _T2>
  660. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  661. auto operator()(_T1&& __t, _T2&& __u) const
  662. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
  663. -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
  664. { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
  665. typedef void is_transparent;
  666. };
  667. #endif
  668. #if _LIBCPP_STD_VER > 11
  669. template <class _Tp = void>
  670. #else
  671. template <class _Tp>
  672. #endif
  673. struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
  674. {
  675. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  676. bool operator()(const _Tp& __x, const _Tp& __y) const
  677. {return __x && __y;}
  678. };
  679. #if _LIBCPP_STD_VER > 11
  680. template <>
  681. struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
  682. {
  683. template <class _T1, class _T2>
  684. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  685. auto operator()(_T1&& __t, _T2&& __u) const
  686. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
  687. -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
  688. { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
  689. typedef void is_transparent;
  690. };
  691. #endif
  692. #if _LIBCPP_STD_VER > 11
  693. template <class _Tp = void>
  694. #else
  695. template <class _Tp>
  696. #endif
  697. struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
  698. {
  699. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  700. bool operator()(const _Tp& __x, const _Tp& __y) const
  701. {return __x || __y;}
  702. };
  703. #if _LIBCPP_STD_VER > 11
  704. template <>
  705. struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
  706. {
  707. template <class _T1, class _T2>
  708. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  709. auto operator()(_T1&& __t, _T2&& __u) const
  710. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
  711. -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
  712. { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
  713. typedef void is_transparent;
  714. };
  715. #endif
  716. #if _LIBCPP_STD_VER > 11
  717. template <class _Tp = void>
  718. #else
  719. template <class _Tp>
  720. #endif
  721. struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
  722. {
  723. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  724. bool operator()(const _Tp& __x) const
  725. {return !__x;}
  726. };
  727. #if _LIBCPP_STD_VER > 11
  728. template <>
  729. struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
  730. {
  731. template <class _Tp>
  732. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  733. auto operator()(_Tp&& __x) const
  734. _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
  735. -> decltype (!_VSTD::forward<_Tp>(__x))
  736. { return !_VSTD::forward<_Tp>(__x); }
  737. typedef void is_transparent;
  738. };
  739. #endif
  740. #if _LIBCPP_STD_VER > 11
  741. template <class _Tp = void>
  742. #else
  743. template <class _Tp>
  744. #endif
  745. struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
  746. {
  747. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  748. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  749. {return __x & __y;}
  750. };
  751. #if _LIBCPP_STD_VER > 11
  752. template <>
  753. struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
  754. {
  755. template <class _T1, class _T2>
  756. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  757. auto operator()(_T1&& __t, _T2&& __u) const
  758. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
  759. -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
  760. { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
  761. typedef void is_transparent;
  762. };
  763. #endif
  764. #if _LIBCPP_STD_VER > 11
  765. template <class _Tp = void>
  766. #else
  767. template <class _Tp>
  768. #endif
  769. struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
  770. {
  771. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  772. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  773. {return __x | __y;}
  774. };
  775. #if _LIBCPP_STD_VER > 11
  776. template <>
  777. struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
  778. {
  779. template <class _T1, class _T2>
  780. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  781. auto operator()(_T1&& __t, _T2&& __u) const
  782. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
  783. -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
  784. { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
  785. typedef void is_transparent;
  786. };
  787. #endif
  788. #if _LIBCPP_STD_VER > 11
  789. template <class _Tp = void>
  790. #else
  791. template <class _Tp>
  792. #endif
  793. struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
  794. {
  795. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  796. _Tp operator()(const _Tp& __x, const _Tp& __y) const
  797. {return __x ^ __y;}
  798. };
  799. #if _LIBCPP_STD_VER > 11
  800. template <>
  801. struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
  802. {
  803. template <class _T1, class _T2>
  804. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  805. auto operator()(_T1&& __t, _T2&& __u) const
  806. _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
  807. -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
  808. { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
  809. typedef void is_transparent;
  810. };
  811. #endif
  812. #if _LIBCPP_STD_VER > 11
  813. template <class _Tp = void>
  814. struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
  815. {
  816. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  817. _Tp operator()(const _Tp& __x) const
  818. {return ~__x;}
  819. };
  820. template <>
  821. struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
  822. {
  823. template <class _Tp>
  824. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  825. auto operator()(_Tp&& __x) const
  826. _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
  827. -> decltype (~_VSTD::forward<_Tp>(__x))
  828. { return ~_VSTD::forward<_Tp>(__x); }
  829. typedef void is_transparent;
  830. };
  831. #endif
  832. template <class _Predicate>
  833. class _LIBCPP_TYPE_VIS_ONLY unary_negate
  834. : public unary_function<typename _Predicate::argument_type, bool>
  835. {
  836. _Predicate __pred_;
  837. public:
  838. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  839. explicit unary_negate(const _Predicate& __pred)
  840. : __pred_(__pred) {}
  841. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  842. bool operator()(const typename _Predicate::argument_type& __x) const
  843. {return !__pred_(__x);}
  844. };
  845. template <class _Predicate>
  846. inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  847. unary_negate<_Predicate>
  848. not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
  849. template <class _Predicate>
  850. class _LIBCPP_TYPE_VIS_ONLY binary_negate
  851. : public binary_function<typename _Predicate::first_argument_type,
  852. typename _Predicate::second_argument_type,
  853. bool>
  854. {
  855. _Predicate __pred_;
  856. public:
  857. _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
  858. binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
  859. _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  860. bool operator()(const typename _Predicate::first_argument_type& __x,
  861. const typename _Predicate::second_argument_type& __y) const
  862. {return !__pred_(__x, __y);}
  863. };
  864. template <class _Predicate>
  865. inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
  866. binary_negate<_Predicate>
  867. not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
  868. template <class __Operation>
  869. class _LIBCPP_TYPE_VIS_ONLY binder1st
  870. : public unary_function<typename __Operation::second_argument_type,
  871. typename __Operation::result_type>
  872. {
  873. protected:
  874. __Operation op;
  875. typename __Operation::first_argument_type value;
  876. public:
  877. _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
  878. const typename __Operation::first_argument_type __y)
  879. : op(__x), value(__y) {}
  880. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  881. (typename __Operation::second_argument_type& __x) const
  882. {return op(value, __x);}
  883. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  884. (const typename __Operation::second_argument_type& __x) const
  885. {return op(value, __x);}
  886. };
  887. template <class __Operation, class _Tp>
  888. inline _LIBCPP_INLINE_VISIBILITY
  889. binder1st<__Operation>
  890. bind1st(const __Operation& __op, const _Tp& __x)
  891. {return binder1st<__Operation>(__op, __x);}
  892. template <class __Operation>
  893. class _LIBCPP_TYPE_VIS_ONLY binder2nd
  894. : public unary_function<typename __Operation::first_argument_type,
  895. typename __Operation::result_type>
  896. {
  897. protected:
  898. __Operation op;
  899. typename __Operation::second_argument_type value;
  900. public:
  901. _LIBCPP_INLINE_VISIBILITY
  902. binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
  903. : op(__x), value(__y) {}
  904. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  905. ( typename __Operation::first_argument_type& __x) const
  906. {return op(__x, value);}
  907. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  908. (const typename __Operation::first_argument_type& __x) const
  909. {return op(__x, value);}
  910. };
  911. template <class __Operation, class _Tp>
  912. inline _LIBCPP_INLINE_VISIBILITY
  913. binder2nd<__Operation>
  914. bind2nd(const __Operation& __op, const _Tp& __x)
  915. {return binder2nd<__Operation>(__op, __x);}
  916. template <class _Arg, class _Result>
  917. class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
  918. : public unary_function<_Arg, _Result>
  919. {
  920. _Result (*__f_)(_Arg);
  921. public:
  922. _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
  923. : __f_(__f) {}
  924. _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
  925. {return __f_(__x);}
  926. };
  927. template <class _Arg, class _Result>
  928. inline _LIBCPP_INLINE_VISIBILITY
  929. pointer_to_unary_function<_Arg,_Result>
  930. ptr_fun(_Result (*__f)(_Arg))
  931. {return pointer_to_unary_function<_Arg,_Result>(__f);}
  932. template <class _Arg1, class _Arg2, class _Result>
  933. class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
  934. : public binary_function<_Arg1, _Arg2, _Result>
  935. {
  936. _Result (*__f_)(_Arg1, _Arg2);
  937. public:
  938. _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
  939. : __f_(__f) {}
  940. _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
  941. {return __f_(__x, __y);}
  942. };
  943. template <class _Arg1, class _Arg2, class _Result>
  944. inline _LIBCPP_INLINE_VISIBILITY
  945. pointer_to_binary_function<_Arg1,_Arg2,_Result>
  946. ptr_fun(_Result (*__f)(_Arg1,_Arg2))
  947. {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
  948. template<class _Sp, class _Tp>
  949. class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
  950. {
  951. _Sp (_Tp::*__p_)();
  952. public:
  953. _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
  954. : __p_(__p) {}
  955. _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
  956. {return (__p->*__p_)();}
  957. };
  958. template<class _Sp, class _Tp, class _Ap>
  959. class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
  960. {
  961. _Sp (_Tp::*__p_)(_Ap);
  962. public:
  963. _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
  964. : __p_(__p) {}
  965. _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
  966. {return (__p->*__p_)(__x);}
  967. };
  968. template<class _Sp, class _Tp>
  969. inline _LIBCPP_INLINE_VISIBILITY
  970. mem_fun_t<_Sp,_Tp>
  971. mem_fun(_Sp (_Tp::*__f)())
  972. {return mem_fun_t<_Sp,_Tp>(__f);}
  973. template<class _Sp, class _Tp, class _Ap>
  974. inline _LIBCPP_INLINE_VISIBILITY
  975. mem_fun1_t<_Sp,_Tp,_Ap>
  976. mem_fun(_Sp (_Tp::*__f)(_Ap))
  977. {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
  978. template<class _Sp, class _Tp>
  979. class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
  980. {
  981. _Sp (_Tp::*__p_)();
  982. public:
  983. _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
  984. : __p_(__p) {}
  985. _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
  986. {return (__p.*__p_)();}
  987. };
  988. template<class _Sp, class _Tp, class _Ap>
  989. class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
  990. {
  991. _Sp (_Tp::*__p_)(_Ap);
  992. public:
  993. _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
  994. : __p_(__p) {}
  995. _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
  996. {return (__p.*__p_)(__x);}
  997. };
  998. template<class _Sp, class _Tp>
  999. inline _LIBCPP_INLINE_VISIBILITY
  1000. mem_fun_ref_t<_Sp,_Tp>
  1001. mem_fun_ref(_Sp (_Tp::*__f)())
  1002. {return mem_fun_ref_t<_Sp,_Tp>(__f);}
  1003. template<class _Sp, class _Tp, class _Ap>
  1004. inline _LIBCPP_INLINE_VISIBILITY
  1005. mem_fun1_ref_t<_Sp,_Tp,_Ap>
  1006. mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
  1007. {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
  1008. template <class _Sp, class _Tp>
  1009. class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
  1010. {
  1011. _Sp (_Tp::*__p_)() const;
  1012. public:
  1013. _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
  1014. : __p_(__p) {}
  1015. _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
  1016. {return (__p->*__p_)();}
  1017. };
  1018. template <class _Sp, class _Tp, class _Ap>
  1019. class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
  1020. {
  1021. _Sp (_Tp::*__p_)(_Ap) const;
  1022. public:
  1023. _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
  1024. : __p_(__p) {}
  1025. _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
  1026. {return (__p->*__p_)(__x);}
  1027. };
  1028. template <class _Sp, class _Tp>
  1029. inline _LIBCPP_INLINE_VISIBILITY
  1030. const_mem_fun_t<_Sp,_Tp>
  1031. mem_fun(_Sp (_Tp::*__f)() const)
  1032. {return const_mem_fun_t<_Sp,_Tp>(__f);}
  1033. template <class _Sp, class _Tp, class _Ap>
  1034. inline _LIBCPP_INLINE_VISIBILITY
  1035. const_mem_fun1_t<_Sp,_Tp,_Ap>
  1036. mem_fun(_Sp (_Tp::*__f)(_Ap) const)
  1037. {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
  1038. template <class _Sp, class _Tp>
  1039. class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
  1040. {
  1041. _Sp (_Tp::*__p_)() const;
  1042. public:
  1043. _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
  1044. : __p_(__p) {}
  1045. _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
  1046. {return (__p.*__p_)();}
  1047. };
  1048. template <class _Sp, class _Tp, class _Ap>
  1049. class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
  1050. : public binary_function<_Tp, _Ap, _Sp>
  1051. {
  1052. _Sp (_Tp::*__p_)(_Ap) const;
  1053. public:
  1054. _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
  1055. : __p_(__p) {}
  1056. _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
  1057. {return (__p.*__p_)(__x);}
  1058. };
  1059. template <class _Sp, class _Tp>
  1060. inline _LIBCPP_INLINE_VISIBILITY
  1061. const_mem_fun_ref_t<_Sp,_Tp>
  1062. mem_fun_ref(_Sp (_Tp::*__f)() const)
  1063. {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
  1064. template <class _Sp, class _Tp, class _Ap>
  1065. inline _LIBCPP_INLINE_VISIBILITY
  1066. const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
  1067. mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
  1068. {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
  1069. ////////////////////////////////////////////////////////////////////////////////
  1070. // MEMFUN
  1071. //==============================================================================
  1072. template <class _Tp>
  1073. class __mem_fn
  1074. : public __weak_result_type<_Tp>
  1075. {
  1076. public:
  1077. // types
  1078. typedef _Tp type;
  1079. private:
  1080. type __f_;
  1081. public:
  1082. _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
  1083. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1084. // invoke
  1085. template <class... _ArgTypes>
  1086. _LIBCPP_INLINE_VISIBILITY
  1087. typename __invoke_return<type, _ArgTypes...>::type
  1088. operator() (_ArgTypes&&... __args) const {
  1089. return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
  1090. }
  1091. #else
  1092. template <class _A0>
  1093. _LIBCPP_INLINE_VISIBILITY
  1094. typename __invoke_return0<type, _A0>::type
  1095. operator() (_A0& __a0) const {
  1096. return __invoke(__f_, __a0);
  1097. }
  1098. template <class _A0>
  1099. _LIBCPP_INLINE_VISIBILITY
  1100. typename __invoke_return0<type, _A0 const>::type
  1101. operator() (_A0 const& __a0) const {
  1102. return __invoke(__f_, __a0);
  1103. }
  1104. template <class _A0, class _A1>
  1105. _LIBCPP_INLINE_VISIBILITY
  1106. typename __invoke_return1<type, _A0, _A1>::type
  1107. operator() (_A0& __a0, _A1& __a1) const {
  1108. return __invoke(__f_, __a0, __a1);
  1109. }
  1110. template <class _A0, class _A1>
  1111. _LIBCPP_INLINE_VISIBILITY
  1112. typename __invoke_return1<type, _A0 const, _A1>::type
  1113. operator() (_A0 const& __a0, _A1& __a1) const {
  1114. return __invoke(__f_, __a0, __a1);
  1115. }
  1116. template <class _A0, class _A1>
  1117. _LIBCPP_INLINE_VISIBILITY
  1118. typename __invoke_return1<type, _A0, _A1 const>::type
  1119. operator() (_A0& __a0, _A1 const& __a1) const {
  1120. return __invoke(__f_, __a0, __a1);
  1121. }
  1122. template <class _A0, class _A1>
  1123. _LIBCPP_INLINE_VISIBILITY
  1124. typename __invoke_return1<type, _A0 const, _A1 const>::type
  1125. operator() (_A0 const& __a0, _A1 const& __a1) const {
  1126. return __invoke(__f_, __a0, __a1);
  1127. }
  1128. template <class _A0, class _A1, class _A2>
  1129. _LIBCPP_INLINE_VISIBILITY
  1130. typename __invoke_return2<type, _A0, _A1, _A2>::type
  1131. operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
  1132. return __invoke(__f_, __a0, __a1, __a2);
  1133. }
  1134. template <class _A0, class _A1, class _A2>
  1135. _LIBCPP_INLINE_VISIBILITY
  1136. typename __invoke_return2<type, _A0 const, _A1, _A2>::type
  1137. operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
  1138. return __invoke(__f_, __a0, __a1, __a2);
  1139. }
  1140. template <class _A0, class _A1, class _A2>
  1141. _LIBCPP_INLINE_VISIBILITY
  1142. typename __invoke_return2<type, _A0, _A1 const, _A2>::type
  1143. operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
  1144. return __invoke(__f_, __a0, __a1, __a2);
  1145. }
  1146. template <class _A0, class _A1, class _A2>
  1147. _LIBCPP_INLINE_VISIBILITY
  1148. typename __invoke_return2<type, _A0, _A1, _A2 const>::type
  1149. operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
  1150. return __invoke(__f_, __a0, __a1, __a2);
  1151. }
  1152. template <class _A0, class _A1, class _A2>
  1153. _LIBCPP_INLINE_VISIBILITY
  1154. typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
  1155. operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
  1156. return __invoke(__f_, __a0, __a1, __a2);
  1157. }
  1158. template <class _A0, class _A1, class _A2>
  1159. _LIBCPP_INLINE_VISIBILITY
  1160. typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
  1161. operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
  1162. return __invoke(__f_, __a0, __a1, __a2);
  1163. }
  1164. template <class _A0, class _A1, class _A2>
  1165. _LIBCPP_INLINE_VISIBILITY
  1166. typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
  1167. operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
  1168. return __invoke(__f_, __a0, __a1, __a2);
  1169. }
  1170. template <class _A0, class _A1, class _A2>
  1171. _LIBCPP_INLINE_VISIBILITY
  1172. typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
  1173. operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
  1174. return __invoke(__f_, __a0, __a1, __a2);
  1175. }
  1176. #endif
  1177. };
  1178. template<class _Rp, class _Tp>
  1179. inline _LIBCPP_INLINE_VISIBILITY
  1180. __mem_fn<_Rp _Tp::*>
  1181. mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
  1182. {
  1183. return __mem_fn<_Rp _Tp::*>(__pm);
  1184. }
  1185. ////////////////////////////////////////////////////////////////////////////////
  1186. // FUNCTION
  1187. //==============================================================================
  1188. // bad_function_call
  1189. class _LIBCPP_EXCEPTION_ABI bad_function_call
  1190. : public exception
  1191. {
  1192. };
  1193. template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
  1194. namespace __function
  1195. {
  1196. template<class _Rp>
  1197. struct __maybe_derive_from_unary_function
  1198. {
  1199. };
  1200. template<class _Rp, class _A1>
  1201. struct __maybe_derive_from_unary_function<_Rp(_A1)>
  1202. : public unary_function<_A1, _Rp>
  1203. {
  1204. };
  1205. template<class _Rp>
  1206. struct __maybe_derive_from_binary_function
  1207. {
  1208. };
  1209. template<class _Rp, class _A1, class _A2>
  1210. struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
  1211. : public binary_function<_A1, _A2, _Rp>
  1212. {
  1213. };
  1214. template <class _Fp>
  1215. _LIBCPP_INLINE_VISIBILITY
  1216. bool __not_null(_Fp const&) { return true; }
  1217. template <class _Fp>
  1218. _LIBCPP_INLINE_VISIBILITY
  1219. bool __not_null(_Fp* __ptr) { return __ptr; }
  1220. template <class _Ret, class _Class>
  1221. _LIBCPP_INLINE_VISIBILITY
  1222. bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
  1223. template <class _Fp>
  1224. _LIBCPP_INLINE_VISIBILITY
  1225. bool __not_null(function<_Fp> const& __f) { return !!__f; }
  1226. } // namespace __function
  1227. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1228. namespace __function {
  1229. template<class _Fp> class __base;
  1230. template<class _Rp, class ..._ArgTypes>
  1231. class __base<_Rp(_ArgTypes...)>
  1232. {
  1233. __base(const __base&);
  1234. __base& operator=(const __base&);
  1235. public:
  1236. _LIBCPP_INLINE_VISIBILITY __base() {}
  1237. _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
  1238. virtual __base* __clone() const = 0;
  1239. virtual void __clone(__base*) const = 0;
  1240. virtual void destroy() _NOEXCEPT = 0;
  1241. virtual void destroy_deallocate() _NOEXCEPT = 0;
  1242. virtual _Rp operator()(_ArgTypes&& ...) = 0;
  1243. #ifndef _LIBCPP_NO_RTTI
  1244. virtual const void* target(const type_info&) const _NOEXCEPT = 0;
  1245. virtual const std::type_info& target_type() const _NOEXCEPT = 0;
  1246. #endif // _LIBCPP_NO_RTTI
  1247. };
  1248. template<class _FD, class _Alloc, class _FB> class __func;
  1249. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1250. class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
  1251. : public __base<_Rp(_ArgTypes...)>
  1252. {
  1253. __compressed_pair<_Fp, _Alloc> __f_;
  1254. public:
  1255. _LIBCPP_INLINE_VISIBILITY
  1256. explicit __func(_Fp&& __f)
  1257. : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
  1258. _VSTD::forward_as_tuple()) {}
  1259. _LIBCPP_INLINE_VISIBILITY
  1260. explicit __func(const _Fp& __f, const _Alloc& __a)
  1261. : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
  1262. _VSTD::forward_as_tuple(__a)) {}
  1263. _LIBCPP_INLINE_VISIBILITY
  1264. explicit __func(const _Fp& __f, _Alloc&& __a)
  1265. : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
  1266. _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
  1267. _LIBCPP_INLINE_VISIBILITY
  1268. explicit __func(_Fp&& __f, _Alloc&& __a)
  1269. : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
  1270. _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
  1271. virtual __base<_Rp(_ArgTypes...)>* __clone() const;
  1272. virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
  1273. virtual void destroy() _NOEXCEPT;
  1274. virtual void destroy_deallocate() _NOEXCEPT;
  1275. virtual _Rp operator()(_ArgTypes&& ... __arg);
  1276. #ifndef _LIBCPP_NO_RTTI
  1277. virtual const void* target(const type_info&) const _NOEXCEPT;
  1278. virtual const std::type_info& target_type() const _NOEXCEPT;
  1279. #endif // _LIBCPP_NO_RTTI
  1280. };
  1281. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1282. __base<_Rp(_ArgTypes...)>*
  1283. __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
  1284. {
  1285. typedef allocator_traits<_Alloc> __alloc_traits;
  1286. typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
  1287. _Ap __a(__f_.second());
  1288. typedef __allocator_destructor<_Ap> _Dp;
  1289. unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
  1290. ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
  1291. return __hold.release();
  1292. }
  1293. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1294. void
  1295. __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
  1296. {
  1297. ::new (__p) __func(__f_.first(), __f_.second());
  1298. }
  1299. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1300. void
  1301. __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
  1302. {
  1303. __f_.~__compressed_pair<_Fp, _Alloc>();
  1304. }
  1305. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1306. void
  1307. __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
  1308. {
  1309. typedef allocator_traits<_Alloc> __alloc_traits;
  1310. typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
  1311. _Ap __a(__f_.second());
  1312. __f_.~__compressed_pair<_Fp, _Alloc>();
  1313. __a.deallocate(this, 1);
  1314. }
  1315. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1316. _Rp
  1317. __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
  1318. {
  1319. typedef __invoke_void_return_wrapper<_Rp> _Invoker;
  1320. return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
  1321. }
  1322. #ifndef _LIBCPP_NO_RTTI
  1323. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1324. const void*
  1325. __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
  1326. {
  1327. if (__ti == typeid(_Fp))
  1328. return &__f_.first();
  1329. return (const void*)0;
  1330. }
  1331. template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
  1332. const std::type_info&
  1333. __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
  1334. {
  1335. return typeid(_Fp);
  1336. }
  1337. #endif // _LIBCPP_NO_RTTI
  1338. } // __function
  1339. template<class _Rp, class ..._ArgTypes>
  1340. class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
  1341. : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
  1342. public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
  1343. {
  1344. typedef __function::__base<_Rp(_ArgTypes...)> __base;
  1345. typename aligned_storage<3*sizeof(void*)>::type __buf_;
  1346. __base* __f_;
  1347. _LIBCPP_NO_CFI static __base *__as_base(void *p) {
  1348. return reinterpret_cast<__base*>(p);
  1349. }
  1350. template <class _Fp, bool = !is_same<_Fp, function>::value &&
  1351. __invokable<_Fp&, _ArgTypes...>::value>
  1352. struct __callable;
  1353. template <class _Fp>
  1354. struct __callable<_Fp, true>
  1355. {
  1356. static const bool value = is_same<void, _Rp>::value ||
  1357. is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
  1358. _Rp>::value;
  1359. };
  1360. template <class _Fp>
  1361. struct __callable<_Fp, false>
  1362. {
  1363. static const bool value = false;
  1364. };
  1365. public:
  1366. typedef _Rp result_type;
  1367. // construct/copy/destroy:
  1368. _LIBCPP_INLINE_VISIBILITY
  1369. function() _NOEXCEPT : __f_(0) {}
  1370. _LIBCPP_INLINE_VISIBILITY
  1371. function(nullptr_t) _NOEXCEPT : __f_(0) {}
  1372. function(const function&);
  1373. function(function&&) _NOEXCEPT;
  1374. template<class _Fp>
  1375. function(_Fp, typename enable_if
  1376. <
  1377. __callable<_Fp>::value &&
  1378. !is_same<_Fp, function>::value
  1379. >::type* = 0);
  1380. template<class _Alloc>
  1381. _LIBCPP_INLINE_VISIBILITY
  1382. function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
  1383. template<class _Alloc>
  1384. _LIBCPP_INLINE_VISIBILITY
  1385. function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
  1386. template<class _Alloc>
  1387. function(allocator_arg_t, const _Alloc&, const function&);
  1388. template<class _Alloc>
  1389. function(allocator_arg_t, const _Alloc&, function&&);
  1390. template<class _Fp, class _Alloc>
  1391. function(allocator_arg_t, const _Alloc& __a, _Fp __f,
  1392. typename enable_if<__callable<_Fp>::value>::type* = 0);
  1393. function& operator=(const function&);
  1394. function& operator=(function&&) _NOEXCEPT;
  1395. function& operator=(nullptr_t) _NOEXCEPT;
  1396. template<class _Fp>
  1397. typename enable_if
  1398. <
  1399. __callable<typename decay<_Fp>::type>::value &&
  1400. !is_same<typename remove_reference<_Fp>::type, function>::value,
  1401. function&
  1402. >::type
  1403. operator=(_Fp&&);
  1404. ~function();
  1405. // function modifiers:
  1406. void swap(function&) _NOEXCEPT;
  1407. #if _LIBCPP_STD_VER <= 14
  1408. template<class _Fp, class _Alloc>
  1409. _LIBCPP_INLINE_VISIBILITY
  1410. void assign(_Fp&& __f, const _Alloc& __a)
  1411. {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
  1412. #endif
  1413. // function capacity:
  1414. _LIBCPP_INLINE_VISIBILITY
  1415. _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
  1416. // deleted overloads close possible hole in the type system
  1417. template<class _R2, class... _ArgTypes2>
  1418. bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
  1419. template<class _R2, class... _ArgTypes2>
  1420. bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
  1421. public:
  1422. // function invocation:
  1423. _Rp operator()(_ArgTypes...) const;
  1424. #ifndef _LIBCPP_NO_RTTI
  1425. // function target access:
  1426. const std::type_info& target_type() const _NOEXCEPT;
  1427. template <typename _Tp> _Tp* target() _NOEXCEPT;
  1428. template <typename _Tp> const _Tp* target() const _NOEXCEPT;
  1429. #endif // _LIBCPP_NO_RTTI
  1430. };
  1431. template<class _Rp, class ..._ArgTypes>
  1432. function<_Rp(_ArgTypes...)>::function(const function& __f)
  1433. {
  1434. if (__f.__f_ == 0)
  1435. __f_ = 0;
  1436. else if ((void *)__f.__f_ == &__f.__buf_)
  1437. {
  1438. __f_ = __as_base(&__buf_);
  1439. __f.__f_->__clone(__f_);
  1440. }
  1441. else
  1442. __f_ = __f.__f_->__clone();
  1443. }
  1444. template<class _Rp, class ..._ArgTypes>
  1445. template <class _Alloc>
  1446. function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
  1447. const function& __f)
  1448. {
  1449. if (__f.__f_ == 0)
  1450. __f_ = 0;
  1451. else if ((void *)__f.__f_ == &__f.__buf_)
  1452. {
  1453. __f_ = __as_base(&__buf_);
  1454. __f.__f_->__clone(__f_);
  1455. }
  1456. else
  1457. __f_ = __f.__f_->__clone();
  1458. }
  1459. template<class _Rp, class ..._ArgTypes>
  1460. function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
  1461. {
  1462. if (__f.__f_ == 0)
  1463. __f_ = 0;
  1464. else if ((void *)__f.__f_ == &__f.__buf_)
  1465. {
  1466. __f_ = __as_base(&__buf_);
  1467. __f.__f_->__clone(__f_);
  1468. }
  1469. else
  1470. {
  1471. __f_ = __f.__f_;
  1472. __f.__f_ = 0;
  1473. }
  1474. }
  1475. template<class _Rp, class ..._ArgTypes>
  1476. template <class _Alloc>
  1477. function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
  1478. function&& __f)
  1479. {
  1480. if (__f.__f_ == 0)
  1481. __f_ = 0;
  1482. else if ((void *)__f.__f_ == &__f.__buf_)
  1483. {
  1484. __f_ = __as_base(&__buf_);
  1485. __f.__f_->__clone(__f_);
  1486. }
  1487. else
  1488. {
  1489. __f_ = __f.__f_;
  1490. __f.__f_ = 0;
  1491. }
  1492. }
  1493. template<class _Rp, class ..._ArgTypes>
  1494. template <class _Fp>
  1495. function<_Rp(_ArgTypes...)>::function(_Fp __f,
  1496. typename enable_if
  1497. <
  1498. __callable<_Fp>::value &&
  1499. !is_same<_Fp, function>::value
  1500. >::type*)
  1501. : __f_(0)
  1502. {
  1503. if (__function::__not_null(__f))
  1504. {
  1505. typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
  1506. if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
  1507. {
  1508. __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
  1509. }
  1510. else
  1511. {
  1512. typedef allocator<_FF> _Ap;
  1513. _Ap __a;
  1514. typedef __allocator_destructor<_Ap> _Dp;
  1515. unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
  1516. ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
  1517. __f_ = __hold.release();
  1518. }
  1519. }
  1520. }
  1521. template<class _Rp, class ..._ArgTypes>
  1522. template <class _Fp, class _Alloc>
  1523. function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
  1524. typename enable_if<__callable<_Fp>::value>::type*)
  1525. : __f_(0)
  1526. {
  1527. typedef allocator_traits<_Alloc> __alloc_traits;
  1528. if (__function::__not_null(__f))
  1529. {
  1530. typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
  1531. typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
  1532. _Ap __a(__a0);
  1533. if (sizeof(_FF) <= sizeof(__buf_) &&
  1534. is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
  1535. {
  1536. __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
  1537. }
  1538. else
  1539. {
  1540. typedef __allocator_destructor<_Ap> _Dp;
  1541. unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
  1542. ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
  1543. __f_ = __hold.release();
  1544. }
  1545. }
  1546. }
  1547. template<class _Rp, class ..._ArgTypes>
  1548. function<_Rp(_ArgTypes...)>&
  1549. function<_Rp(_ArgTypes...)>::operator=(const function& __f)
  1550. {
  1551. function(__f).swap(*this);
  1552. return *this;
  1553. }
  1554. template<class _Rp, class ..._ArgTypes>
  1555. function<_Rp(_ArgTypes...)>&
  1556. function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
  1557. {
  1558. if ((void *)__f_ == &__buf_)
  1559. __f_->destroy();
  1560. else if (__f_)
  1561. __f_->destroy_deallocate();
  1562. __f_ = 0;
  1563. if (__f.__f_ == 0)
  1564. __f_ = 0;
  1565. else if ((void *)__f.__f_ == &__f.__buf_)
  1566. {
  1567. __f_ = __as_base(&__buf_);
  1568. __f.__f_->__clone(__f_);
  1569. }
  1570. else
  1571. {
  1572. __f_ = __f.__f_;
  1573. __f.__f_ = 0;
  1574. }
  1575. return *this;
  1576. }
  1577. template<class _Rp, class ..._ArgTypes>
  1578. function<_Rp(_ArgTypes...)>&
  1579. function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
  1580. {
  1581. if ((void *)__f_ == &__buf_)
  1582. __f_->destroy();
  1583. else if (__f_)
  1584. __f_->destroy_deallocate();
  1585. __f_ = 0;
  1586. return *this;
  1587. }
  1588. template<class _Rp, class ..._ArgTypes>
  1589. template <class _Fp>
  1590. typename enable_if
  1591. <
  1592. function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
  1593. !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
  1594. function<_Rp(_ArgTypes...)>&
  1595. >::type
  1596. function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
  1597. {
  1598. function(_VSTD::forward<_Fp>(__f)).swap(*this);
  1599. return *this;
  1600. }
  1601. template<class _Rp, class ..._ArgTypes>
  1602. function<_Rp(_ArgTypes...)>::~function()
  1603. {
  1604. if ((void *)__f_ == &__buf_)
  1605. __f_->destroy();
  1606. else if (__f_)
  1607. __f_->destroy_deallocate();
  1608. }
  1609. template<class _Rp, class ..._ArgTypes>
  1610. void
  1611. function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
  1612. {
  1613. if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
  1614. {
  1615. typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
  1616. __base* __t = __as_base(&__tempbuf);
  1617. __f_->__clone(__t);
  1618. __f_->destroy();
  1619. __f_ = 0;
  1620. __f.__f_->__clone(__as_base(&__buf_));
  1621. __f.__f_->destroy();
  1622. __f.__f_ = 0;
  1623. __f_ = __as_base(&__buf_);
  1624. __t->__clone(__as_base(&__f.__buf_));
  1625. __t->destroy();
  1626. __f.__f_ = __as_base(&__f.__buf_);
  1627. }
  1628. else if ((void *)__f_ == &__buf_)
  1629. {
  1630. __f_->__clone(__as_base(&__f.__buf_));
  1631. __f_->destroy();
  1632. __f_ = __f.__f_;
  1633. __f.__f_ = __as_base(&__f.__buf_);
  1634. }
  1635. else if ((void *)__f.__f_ == &__f.__buf_)
  1636. {
  1637. __f.__f_->__clone(__as_base(&__buf_));
  1638. __f.__f_->destroy();
  1639. __f.__f_ = __f_;
  1640. __f_ = __as_base(&__buf_);
  1641. }
  1642. else
  1643. _VSTD::swap(__f_, __f.__f_);
  1644. }
  1645. template<class _Rp, class ..._ArgTypes>
  1646. _Rp
  1647. function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
  1648. {
  1649. #ifndef _LIBCPP_NO_EXCEPTIONS
  1650. if (__f_ == 0)
  1651. throw bad_function_call();
  1652. #endif // _LIBCPP_NO_EXCEPTIONS
  1653. return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
  1654. }
  1655. #ifndef _LIBCPP_NO_RTTI
  1656. template<class _Rp, class ..._ArgTypes>
  1657. const std::type_info&
  1658. function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
  1659. {
  1660. if (__f_ == 0)
  1661. return typeid(void);
  1662. return __f_->target_type();
  1663. }
  1664. template<class _Rp, class ..._ArgTypes>
  1665. template <typename _Tp>
  1666. _Tp*
  1667. function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
  1668. {
  1669. if (__f_ == 0)
  1670. return (_Tp*)0;
  1671. return (_Tp*)__f_->target(typeid(_Tp));
  1672. }
  1673. template<class _Rp, class ..._ArgTypes>
  1674. template <typename _Tp>
  1675. const _Tp*
  1676. function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
  1677. {
  1678. if (__f_ == 0)
  1679. return (const _Tp*)0;
  1680. return (const _Tp*)__f_->target(typeid(_Tp));
  1681. }
  1682. #endif // _LIBCPP_NO_RTTI
  1683. template <class _Rp, class... _ArgTypes>
  1684. inline _LIBCPP_INLINE_VISIBILITY
  1685. bool
  1686. operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
  1687. template <class _Rp, class... _ArgTypes>
  1688. inline _LIBCPP_INLINE_VISIBILITY
  1689. bool
  1690. operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
  1691. template <class _Rp, class... _ArgTypes>
  1692. inline _LIBCPP_INLINE_VISIBILITY
  1693. bool
  1694. operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
  1695. template <class _Rp, class... _ArgTypes>
  1696. inline _LIBCPP_INLINE_VISIBILITY
  1697. bool
  1698. operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
  1699. template <class _Rp, class... _ArgTypes>
  1700. inline _LIBCPP_INLINE_VISIBILITY
  1701. void
  1702. swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
  1703. {return __x.swap(__y);}
  1704. #else // _LIBCPP_HAS_NO_VARIADICS
  1705. #include <__functional_03>
  1706. #endif
  1707. ////////////////////////////////////////////////////////////////////////////////
  1708. // BIND
  1709. //==============================================================================
  1710. template<class _Tp> struct __is_bind_expression : public false_type {};
  1711. template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
  1712. : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
  1713. template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
  1714. template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
  1715. : public __is_placeholder<typename remove_cv<_Tp>::type> {};
  1716. namespace placeholders
  1717. {
  1718. template <int _Np> struct __ph {};
  1719. #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
  1720. _LIBCPP_FUNC_VIS extern const __ph<1> _1;
  1721. _LIBCPP_FUNC_VIS extern const __ph<2> _2;
  1722. _LIBCPP_FUNC_VIS extern const __ph<3> _3;
  1723. _LIBCPP_FUNC_VIS extern const __ph<4> _4;
  1724. _LIBCPP_FUNC_VIS extern const __ph<5> _5;
  1725. _LIBCPP_FUNC_VIS extern const __ph<6> _6;
  1726. _LIBCPP_FUNC_VIS extern const __ph<7> _7;
  1727. _LIBCPP_FUNC_VIS extern const __ph<8> _8;
  1728. _LIBCPP_FUNC_VIS extern const __ph<9> _9;
  1729. _LIBCPP_FUNC_VIS extern const __ph<10> _10;
  1730. #else
  1731. constexpr __ph<1> _1{};
  1732. constexpr __ph<2> _2{};
  1733. constexpr __ph<3> _3{};
  1734. constexpr __ph<4> _4{};
  1735. constexpr __ph<5> _5{};
  1736. constexpr __ph<6> _6{};
  1737. constexpr __ph<7> _7{};
  1738. constexpr __ph<8> _8{};
  1739. constexpr __ph<9> _9{};
  1740. constexpr __ph<10> _10{};
  1741. #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
  1742. } // placeholders
  1743. template<int _Np>
  1744. struct __is_placeholder<placeholders::__ph<_Np> >
  1745. : public integral_constant<int, _Np> {};
  1746. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1747. template <class _Tp, class _Uj>
  1748. inline _LIBCPP_INLINE_VISIBILITY
  1749. _Tp&
  1750. __mu(reference_wrapper<_Tp> __t, _Uj&)
  1751. {
  1752. return __t.get();
  1753. }
  1754. template <class _Ti, class ..._Uj, size_t ..._Indx>
  1755. inline _LIBCPP_INLINE_VISIBILITY
  1756. typename __invoke_of<_Ti&, _Uj...>::type
  1757. __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
  1758. {
  1759. return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
  1760. }
  1761. template <class _Ti, class ..._Uj>
  1762. inline _LIBCPP_INLINE_VISIBILITY
  1763. typename __lazy_enable_if
  1764. <
  1765. is_bind_expression<_Ti>::value,
  1766. __invoke_of<_Ti&, _Uj...>
  1767. >::type
  1768. __mu(_Ti& __ti, tuple<_Uj...>& __uj)
  1769. {
  1770. typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
  1771. return __mu_expand(__ti, __uj, __indices());
  1772. }
  1773. template <bool IsPh, class _Ti, class _Uj>
  1774. struct __mu_return2 {};
  1775. template <class _Ti, class _Uj>
  1776. struct __mu_return2<true, _Ti, _Uj>
  1777. {
  1778. typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
  1779. };
  1780. template <class _Ti, class _Uj>
  1781. inline _LIBCPP_INLINE_VISIBILITY
  1782. typename enable_if
  1783. <
  1784. 0 < is_placeholder<_Ti>::value,
  1785. typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
  1786. >::type
  1787. __mu(_Ti&, _Uj& __uj)
  1788. {
  1789. const size_t _Indx = is_placeholder<_Ti>::value - 1;
  1790. return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
  1791. }
  1792. template <class _Ti, class _Uj>
  1793. inline _LIBCPP_INLINE_VISIBILITY
  1794. typename enable_if
  1795. <
  1796. !is_bind_expression<_Ti>::value &&
  1797. is_placeholder<_Ti>::value == 0 &&
  1798. !__is_reference_wrapper<_Ti>::value,
  1799. _Ti&
  1800. >::type
  1801. __mu(_Ti& __ti, _Uj&)
  1802. {
  1803. return __ti;
  1804. }
  1805. template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
  1806. class _TupleUj>
  1807. struct ____mu_return;
  1808. template <bool _Invokable, class _Ti, class ..._Uj>
  1809. struct ____mu_return_invokable // false
  1810. {
  1811. typedef __nat type;
  1812. };
  1813. template <class _Ti, class ..._Uj>
  1814. struct ____mu_return_invokable<true, _Ti, _Uj...>
  1815. {
  1816. typedef typename __invoke_of<_Ti&, _Uj...>::type type;
  1817. };
  1818. template <class _Ti, class ..._Uj>
  1819. struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
  1820. : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
  1821. {
  1822. };
  1823. template <class _Ti, class _TupleUj>
  1824. struct ____mu_return<_Ti, false, false, true, _TupleUj>
  1825. {
  1826. typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
  1827. _TupleUj>::type&& type;
  1828. };
  1829. template <class _Ti, class _TupleUj>
  1830. struct ____mu_return<_Ti, true, false, false, _TupleUj>
  1831. {
  1832. typedef typename _Ti::type& type;
  1833. };
  1834. template <class _Ti, class _TupleUj>
  1835. struct ____mu_return<_Ti, false, false, false, _TupleUj>
  1836. {
  1837. typedef _Ti& type;
  1838. };
  1839. template <class _Ti, class _TupleUj>
  1840. struct __mu_return
  1841. : public ____mu_return<_Ti,
  1842. __is_reference_wrapper<_Ti>::value,
  1843. is_bind_expression<_Ti>::value,
  1844. 0 < is_placeholder<_Ti>::value &&
  1845. is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
  1846. _TupleUj>
  1847. {
  1848. };
  1849. template <class _Fp, class _BoundArgs, class _TupleUj>
  1850. struct __is_valid_bind_return
  1851. {
  1852. static const bool value = false;
  1853. };
  1854. template <class _Fp, class ..._BoundArgs, class _TupleUj>
  1855. struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
  1856. {
  1857. static const bool value = __invokable<_Fp,
  1858. typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
  1859. };
  1860. template <class _Fp, class ..._BoundArgs, class _TupleUj>
  1861. struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
  1862. {
  1863. static const bool value = __invokable<_Fp,
  1864. typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
  1865. };
  1866. template <class _Fp, class _BoundArgs, class _TupleUj,
  1867. bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
  1868. struct __bind_return;
  1869. template <class _Fp, class ..._BoundArgs, class _TupleUj>
  1870. struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
  1871. {
  1872. typedef typename __invoke_of
  1873. <
  1874. _Fp&,
  1875. typename __mu_return
  1876. <
  1877. _BoundArgs,
  1878. _TupleUj
  1879. >::type...
  1880. >::type type;
  1881. };
  1882. template <class _Fp, class ..._BoundArgs, class _TupleUj>
  1883. struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
  1884. {
  1885. typedef typename __invoke_of
  1886. <
  1887. _Fp&,
  1888. typename __mu_return
  1889. <
  1890. const _BoundArgs,
  1891. _TupleUj
  1892. >::type...
  1893. >::type type;
  1894. };
  1895. template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
  1896. inline _LIBCPP_INLINE_VISIBILITY
  1897. typename __bind_return<_Fp, _BoundArgs, _Args>::type
  1898. __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
  1899. _Args&& __args)
  1900. {
  1901. return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
  1902. }
  1903. template<class _Fp, class ..._BoundArgs>
  1904. class __bind
  1905. : public __weak_result_type<typename decay<_Fp>::type>
  1906. {
  1907. protected:
  1908. typedef typename decay<_Fp>::type _Fd;
  1909. typedef tuple<typename decay<_BoundArgs>::type...> _Td;
  1910. private:
  1911. _Fd __f_;
  1912. _Td __bound_args_;
  1913. typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
  1914. public:
  1915. #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
  1916. _LIBCPP_INLINE_VISIBILITY
  1917. __bind(const __bind& __b)
  1918. : __f_(__b.__f_),
  1919. __bound_args_(__b.__bound_args_) {}
  1920. _LIBCPP_INLINE_VISIBILITY
  1921. __bind& operator=(const __bind& __b)
  1922. {
  1923. __f_ = __b.__f_;
  1924. __bound_args_ = __b.__bound_args_;
  1925. return *this;
  1926. }
  1927. _LIBCPP_INLINE_VISIBILITY
  1928. __bind(__bind&& __b)
  1929. : __f_(_VSTD::move(__b.__f_)),
  1930. __bound_args_(_VSTD::move(__b.__bound_args_)) {}
  1931. _LIBCPP_INLINE_VISIBILITY
  1932. __bind& operator=(__bind&& __b)
  1933. {
  1934. __f_ = _VSTD::move(__b.__f_);
  1935. __bound_args_ = _VSTD::move(__b.__bound_args_);
  1936. return *this;
  1937. }
  1938. #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
  1939. template <class _Gp, class ..._BA,
  1940. class = typename enable_if
  1941. <
  1942. is_constructible<_Fd, _Gp>::value &&
  1943. !is_same<typename remove_reference<_Gp>::type,
  1944. __bind>::value
  1945. >::type>
  1946. _LIBCPP_INLINE_VISIBILITY
  1947. explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
  1948. : __f_(_VSTD::forward<_Gp>(__f)),
  1949. __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
  1950. template <class ..._Args>
  1951. _LIBCPP_INLINE_VISIBILITY
  1952. typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
  1953. operator()(_Args&& ...__args)
  1954. {
  1955. return __apply_functor(__f_, __bound_args_, __indices(),
  1956. tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
  1957. }
  1958. template <class ..._Args>
  1959. _LIBCPP_INLINE_VISIBILITY
  1960. typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
  1961. operator()(_Args&& ...__args) const
  1962. {
  1963. return __apply_functor(__f_, __bound_args_, __indices(),
  1964. tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
  1965. }
  1966. };
  1967. template<class _Fp, class ..._BoundArgs>
  1968. struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
  1969. template<class _Rp, class _Fp, class ..._BoundArgs>
  1970. class __bind_r
  1971. : public __bind<_Fp, _BoundArgs...>
  1972. {
  1973. typedef __bind<_Fp, _BoundArgs...> base;
  1974. typedef typename base::_Fd _Fd;
  1975. typedef typename base::_Td _Td;
  1976. public:
  1977. typedef _Rp result_type;
  1978. #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
  1979. _LIBCPP_INLINE_VISIBILITY
  1980. __bind_r(const __bind_r& __b)
  1981. : base(_VSTD::forward<const base&>(__b)) {}
  1982. _LIBCPP_INLINE_VISIBILITY
  1983. __bind_r& operator=(const __bind_r& __b)
  1984. {
  1985. base::operator=(_VSTD::forward<const base&>(__b));
  1986. return *this;
  1987. }
  1988. _LIBCPP_INLINE_VISIBILITY
  1989. __bind_r(__bind_r&& __b)
  1990. : base(_VSTD::forward<base>(__b)) {}
  1991. _LIBCPP_INLINE_VISIBILITY
  1992. __bind_r& operator=(__bind_r&& __b)
  1993. {
  1994. base::operator=(_VSTD::forward<base>(__b));
  1995. return *this;
  1996. }
  1997. #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
  1998. template <class _Gp, class ..._BA,
  1999. class = typename enable_if
  2000. <
  2001. is_constructible<_Fd, _Gp>::value &&
  2002. !is_same<typename remove_reference<_Gp>::type,
  2003. __bind_r>::value
  2004. >::type>
  2005. _LIBCPP_INLINE_VISIBILITY
  2006. explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
  2007. : base(_VSTD::forward<_Gp>(__f),
  2008. _VSTD::forward<_BA>(__bound_args)...) {}
  2009. template <class ..._Args>
  2010. _LIBCPP_INLINE_VISIBILITY
  2011. typename enable_if
  2012. <
  2013. is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
  2014. result_type>::value || is_void<_Rp>::value,
  2015. result_type
  2016. >::type
  2017. operator()(_Args&& ...__args)
  2018. {
  2019. typedef __invoke_void_return_wrapper<_Rp> _Invoker;
  2020. return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
  2021. }
  2022. template <class ..._Args>
  2023. _LIBCPP_INLINE_VISIBILITY
  2024. typename enable_if
  2025. <
  2026. is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
  2027. result_type>::value || is_void<_Rp>::value,
  2028. result_type
  2029. >::type
  2030. operator()(_Args&& ...__args) const
  2031. {
  2032. typedef __invoke_void_return_wrapper<_Rp> _Invoker;
  2033. return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
  2034. }
  2035. };
  2036. template<class _Rp, class _Fp, class ..._BoundArgs>
  2037. struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
  2038. template<class _Fp, class ..._BoundArgs>
  2039. inline _LIBCPP_INLINE_VISIBILITY
  2040. __bind<_Fp, _BoundArgs...>
  2041. bind(_Fp&& __f, _BoundArgs&&... __bound_args)
  2042. {
  2043. typedef __bind<_Fp, _BoundArgs...> type;
  2044. return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
  2045. }
  2046. template<class _Rp, class _Fp, class ..._BoundArgs>
  2047. inline _LIBCPP_INLINE_VISIBILITY
  2048. __bind_r<_Rp, _Fp, _BoundArgs...>
  2049. bind(_Fp&& __f, _BoundArgs&&... __bound_args)
  2050. {
  2051. typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
  2052. return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
  2053. }
  2054. #endif // _LIBCPP_HAS_NO_VARIADICS
  2055. template <>
  2056. struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
  2057. : public unary_function<bool, size_t>
  2058. {
  2059. _LIBCPP_INLINE_VISIBILITY
  2060. size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2061. };
  2062. template <>
  2063. struct _LIBCPP_TYPE_VIS_ONLY hash<char>
  2064. : public unary_function<char, size_t>
  2065. {
  2066. _LIBCPP_INLINE_VISIBILITY
  2067. size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2068. };
  2069. template <>
  2070. struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
  2071. : public unary_function<signed char, size_t>
  2072. {
  2073. _LIBCPP_INLINE_VISIBILITY
  2074. size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2075. };
  2076. template <>
  2077. struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
  2078. : public unary_function<unsigned char, size_t>
  2079. {
  2080. _LIBCPP_INLINE_VISIBILITY
  2081. size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2082. };
  2083. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  2084. template <>
  2085. struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
  2086. : public unary_function<char16_t, size_t>
  2087. {
  2088. _LIBCPP_INLINE_VISIBILITY
  2089. size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2090. };
  2091. template <>
  2092. struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
  2093. : public unary_function<char32_t, size_t>
  2094. {
  2095. _LIBCPP_INLINE_VISIBILITY
  2096. size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2097. };
  2098. #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
  2099. template <>
  2100. struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
  2101. : public unary_function<wchar_t, size_t>
  2102. {
  2103. _LIBCPP_INLINE_VISIBILITY
  2104. size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2105. };
  2106. template <>
  2107. struct _LIBCPP_TYPE_VIS_ONLY hash<short>
  2108. : public unary_function<short, size_t>
  2109. {
  2110. _LIBCPP_INLINE_VISIBILITY
  2111. size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2112. };
  2113. template <>
  2114. struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
  2115. : public unary_function<unsigned short, size_t>
  2116. {
  2117. _LIBCPP_INLINE_VISIBILITY
  2118. size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2119. };
  2120. template <>
  2121. struct _LIBCPP_TYPE_VIS_ONLY hash<int>
  2122. : public unary_function<int, size_t>
  2123. {
  2124. _LIBCPP_INLINE_VISIBILITY
  2125. size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2126. };
  2127. template <>
  2128. struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
  2129. : public unary_function<unsigned int, size_t>
  2130. {
  2131. _LIBCPP_INLINE_VISIBILITY
  2132. size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2133. };
  2134. template <>
  2135. struct _LIBCPP_TYPE_VIS_ONLY hash<long>
  2136. : public unary_function<long, size_t>
  2137. {
  2138. _LIBCPP_INLINE_VISIBILITY
  2139. size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2140. };
  2141. template <>
  2142. struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
  2143. : public unary_function<unsigned long, size_t>
  2144. {
  2145. _LIBCPP_INLINE_VISIBILITY
  2146. size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
  2147. };
  2148. template <>
  2149. struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
  2150. : public __scalar_hash<long long>
  2151. {
  2152. };
  2153. template <>
  2154. struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
  2155. : public __scalar_hash<unsigned long long>
  2156. {
  2157. };
  2158. #ifndef _LIBCPP_HAS_NO_INT128
  2159. template <>
  2160. struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
  2161. : public __scalar_hash<__int128_t>
  2162. {
  2163. };
  2164. template <>
  2165. struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
  2166. : public __scalar_hash<__uint128_t>
  2167. {
  2168. };
  2169. #endif
  2170. template <>
  2171. struct _LIBCPP_TYPE_VIS_ONLY hash<float>
  2172. : public __scalar_hash<float>
  2173. {
  2174. _LIBCPP_INLINE_VISIBILITY
  2175. size_t operator()(float __v) const _NOEXCEPT
  2176. {
  2177. // -0.0 and 0.0 should return same hash
  2178. if (__v == 0)
  2179. return 0;
  2180. return __scalar_hash<float>::operator()(__v);
  2181. }
  2182. };
  2183. template <>
  2184. struct _LIBCPP_TYPE_VIS_ONLY hash<double>
  2185. : public __scalar_hash<double>
  2186. {
  2187. _LIBCPP_INLINE_VISIBILITY
  2188. size_t operator()(double __v) const _NOEXCEPT
  2189. {
  2190. // -0.0 and 0.0 should return same hash
  2191. if (__v == 0)
  2192. return 0;
  2193. return __scalar_hash<double>::operator()(__v);
  2194. }
  2195. };
  2196. template <>
  2197. struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
  2198. : public __scalar_hash<long double>
  2199. {
  2200. _LIBCPP_INLINE_VISIBILITY
  2201. size_t operator()(long double __v) const _NOEXCEPT
  2202. {
  2203. // -0.0 and 0.0 should return same hash
  2204. if (__v == 0)
  2205. return 0;
  2206. #if defined(__i386__)
  2207. // Zero out padding bits
  2208. union
  2209. {
  2210. long double __t;
  2211. struct
  2212. {
  2213. size_t __a;
  2214. size_t __b;
  2215. size_t __c;
  2216. size_t __d;
  2217. } __s;
  2218. } __u;
  2219. __u.__s.__a = 0;
  2220. __u.__s.__b = 0;
  2221. __u.__s.__c = 0;
  2222. __u.__s.__d = 0;
  2223. __u.__t = __v;
  2224. return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
  2225. #elif defined(__x86_64__)
  2226. // Zero out padding bits
  2227. union
  2228. {
  2229. long double __t;
  2230. struct
  2231. {
  2232. size_t __a;
  2233. size_t __b;
  2234. } __s;
  2235. } __u;
  2236. __u.__s.__a = 0;
  2237. __u.__s.__b = 0;
  2238. __u.__t = __v;
  2239. return __u.__s.__a ^ __u.__s.__b;
  2240. #else
  2241. return __scalar_hash<long double>::operator()(__v);
  2242. #endif
  2243. }
  2244. };
  2245. #if _LIBCPP_STD_VER > 11
  2246. template <class _Tp>
  2247. struct _LIBCPP_TYPE_VIS_ONLY hash
  2248. : public unary_function<_Tp, size_t>
  2249. {
  2250. static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
  2251. _LIBCPP_INLINE_VISIBILITY
  2252. size_t operator()(_Tp __v) const _NOEXCEPT
  2253. {
  2254. typedef typename underlying_type<_Tp>::type type;
  2255. return hash<type>{}(static_cast<type>(__v));
  2256. }
  2257. };
  2258. #endif
  2259. #if _LIBCPP_STD_VER > 14
  2260. template <class _Fn, class ..._Args>
  2261. result_of_t<_Fn&&(_Args&&...)>
  2262. invoke(_Fn&& __f, _Args&&... __args)
  2263. noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
  2264. {
  2265. return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
  2266. }
  2267. template <class _DecayFunc>
  2268. class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp {
  2269. _DecayFunc __fd;
  2270. public:
  2271. __not_fn_imp() = delete;
  2272. template <class ..._Args>
  2273. _LIBCPP_INLINE_VISIBILITY
  2274. auto operator()(_Args&& ...__args) &
  2275. noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
  2276. -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
  2277. { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
  2278. template <class ..._Args>
  2279. _LIBCPP_INLINE_VISIBILITY
  2280. auto operator()(_Args&& ...__args) &&
  2281. noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
  2282. -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
  2283. { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
  2284. template <class ..._Args>
  2285. _LIBCPP_INLINE_VISIBILITY
  2286. auto operator()(_Args&& ...__args) const&
  2287. noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
  2288. -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
  2289. { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
  2290. template <class ..._Args>
  2291. _LIBCPP_INLINE_VISIBILITY
  2292. auto operator()(_Args&& ...__args) const&&
  2293. noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
  2294. -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
  2295. { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
  2296. private:
  2297. template <class _RawFunc,
  2298. class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
  2299. _LIBCPP_INLINE_VISIBILITY
  2300. explicit __not_fn_imp(_RawFunc&& __rf)
  2301. : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
  2302. template <class _RawFunc>
  2303. friend inline _LIBCPP_INLINE_VISIBILITY
  2304. __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
  2305. };
  2306. template <class _RawFunc>
  2307. inline _LIBCPP_INLINE_VISIBILITY
  2308. __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
  2309. return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
  2310. }
  2311. #endif
  2312. // struct hash<T*> in <memory>
  2313. _LIBCPP_END_NAMESPACE_STD
  2314. #endif // _LIBCPP_FUNCTIONAL