10b57cec5SDimitry Andric// -*- C++ -*- 20b57cec5SDimitry Andric//===------------------------ functional ----------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_FUNCTIONAL 110b57cec5SDimitry Andric#define _LIBCPP_FUNCTIONAL 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric functional synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class Arg, class Result> 200b57cec5SDimitry Andricstruct unary_function 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andric typedef Arg argument_type; 230b57cec5SDimitry Andric typedef Result result_type; 240b57cec5SDimitry Andric}; 250b57cec5SDimitry Andric 260b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> 270b57cec5SDimitry Andricstruct binary_function 280b57cec5SDimitry Andric{ 290b57cec5SDimitry Andric typedef Arg1 first_argument_type; 300b57cec5SDimitry Andric typedef Arg2 second_argument_type; 310b57cec5SDimitry Andric typedef Result result_type; 320b57cec5SDimitry Andric}; 330b57cec5SDimitry Andric 340b57cec5SDimitry Andrictemplate <class T> 350b57cec5SDimitry Andricclass reference_wrapper 360b57cec5SDimitry Andric : public unary_function<T1, R> // if wrapping a unary functor 370b57cec5SDimitry Andric : public binary_function<T1, T2, R> // if wraping a binary functor 380b57cec5SDimitry Andric{ 390b57cec5SDimitry Andricpublic: 400b57cec5SDimitry Andric // types 410b57cec5SDimitry Andric typedef T type; 420b57cec5SDimitry Andric typedef see below result_type; // Not always defined 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric // construct/copy/destroy 450b57cec5SDimitry Andric reference_wrapper(T&) noexcept; 460b57cec5SDimitry Andric reference_wrapper(T&&) = delete; // do not bind to temps 470b57cec5SDimitry Andric reference_wrapper(const reference_wrapper<T>& x) noexcept; 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric // assignment 500b57cec5SDimitry Andric reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric // access 530b57cec5SDimitry Andric operator T& () const noexcept; 540b57cec5SDimitry Andric T& get() const noexcept; 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric // invoke 570b57cec5SDimitry Andric template <class... ArgTypes> 580b57cec5SDimitry Andric typename result_of<T&(ArgTypes&&...)>::type 590b57cec5SDimitry Andric operator() (ArgTypes&&...) const; 600b57cec5SDimitry Andric}; 610b57cec5SDimitry Andric 620b57cec5SDimitry Andrictemplate <class T> reference_wrapper<T> ref(T& t) noexcept; 630b57cec5SDimitry Andrictemplate <class T> void ref(const T&& t) = delete; 640b57cec5SDimitry Andrictemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; 650b57cec5SDimitry Andric 660b57cec5SDimitry Andrictemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept; 670b57cec5SDimitry Andrictemplate <class T> void cref(const T&& t) = delete; 680b57cec5SDimitry Andrictemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; 690b57cec5SDimitry Andric 700b57cec5SDimitry Andrictemplate <class T> struct unwrap_reference; // since C++20 710b57cec5SDimitry Andrictemplate <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20 720b57cec5SDimitry Andrictemplate <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20 730b57cec5SDimitry Andrictemplate <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20 740b57cec5SDimitry Andric 750b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 760b57cec5SDimitry Andricstruct plus : binary_function<T, T, T> 770b57cec5SDimitry Andric{ 780b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 790b57cec5SDimitry Andric}; 800b57cec5SDimitry Andric 810b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 820b57cec5SDimitry Andricstruct minus : binary_function<T, T, T> 830b57cec5SDimitry Andric{ 840b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 850b57cec5SDimitry Andric}; 860b57cec5SDimitry Andric 870b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 880b57cec5SDimitry Andricstruct multiplies : binary_function<T, T, T> 890b57cec5SDimitry Andric{ 900b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 910b57cec5SDimitry Andric}; 920b57cec5SDimitry Andric 930b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 940b57cec5SDimitry Andricstruct divides : binary_function<T, T, T> 950b57cec5SDimitry Andric{ 960b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 970b57cec5SDimitry Andric}; 980b57cec5SDimitry Andric 990b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1000b57cec5SDimitry Andricstruct modulus : binary_function<T, T, T> 1010b57cec5SDimitry Andric{ 1020b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 1030b57cec5SDimitry Andric}; 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1060b57cec5SDimitry Andricstruct negate : unary_function<T, T> 1070b57cec5SDimitry Andric{ 1080b57cec5SDimitry Andric T operator()(const T& x) const; 1090b57cec5SDimitry Andric}; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1120b57cec5SDimitry Andricstruct equal_to : binary_function<T, T, bool> 1130b57cec5SDimitry Andric{ 1140b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1150b57cec5SDimitry Andric}; 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1180b57cec5SDimitry Andricstruct not_equal_to : binary_function<T, T, bool> 1190b57cec5SDimitry Andric{ 1200b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1210b57cec5SDimitry Andric}; 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1240b57cec5SDimitry Andricstruct greater : binary_function<T, T, bool> 1250b57cec5SDimitry Andric{ 1260b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1270b57cec5SDimitry Andric}; 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1300b57cec5SDimitry Andricstruct less : binary_function<T, T, bool> 1310b57cec5SDimitry Andric{ 1320b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1330b57cec5SDimitry Andric}; 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1360b57cec5SDimitry Andricstruct greater_equal : binary_function<T, T, bool> 1370b57cec5SDimitry Andric{ 1380b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1390b57cec5SDimitry Andric}; 1400b57cec5SDimitry Andric 1410b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1420b57cec5SDimitry Andricstruct less_equal : binary_function<T, T, bool> 1430b57cec5SDimitry Andric{ 1440b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1450b57cec5SDimitry Andric}; 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1480b57cec5SDimitry Andricstruct logical_and : binary_function<T, T, bool> 1490b57cec5SDimitry Andric{ 1500b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1510b57cec5SDimitry Andric}; 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1540b57cec5SDimitry Andricstruct logical_or : binary_function<T, T, bool> 1550b57cec5SDimitry Andric{ 1560b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1570b57cec5SDimitry Andric}; 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1600b57cec5SDimitry Andricstruct logical_not : unary_function<T, bool> 1610b57cec5SDimitry Andric{ 1620b57cec5SDimitry Andric bool operator()(const T& x) const; 1630b57cec5SDimitry Andric}; 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1660b57cec5SDimitry Andricstruct bit_and : unary_function<T, bool> 1670b57cec5SDimitry Andric{ 1680b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1690b57cec5SDimitry Andric}; 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1720b57cec5SDimitry Andricstruct bit_or : unary_function<T, bool> 1730b57cec5SDimitry Andric{ 1740b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1750b57cec5SDimitry Andric}; 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 1780b57cec5SDimitry Andricstruct bit_xor : unary_function<T, bool> 1790b57cec5SDimitry Andric{ 1800b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1810b57cec5SDimitry Andric}; 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andrictemplate <class T=void> // C++14 1840b57cec5SDimitry Andricstruct bit_xor : unary_function<T, bool> 1850b57cec5SDimitry Andric{ 1860b57cec5SDimitry Andric bool operator()(const T& x) const; 1870b57cec5SDimitry Andric}; 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andrictemplate <class Predicate> 1900b57cec5SDimitry Andricclass unary_negate // deprecated in C++17 1910b57cec5SDimitry Andric : public unary_function<typename Predicate::argument_type, bool> 1920b57cec5SDimitry Andric{ 1930b57cec5SDimitry Andricpublic: 1940b57cec5SDimitry Andric explicit unary_negate(const Predicate& pred); 1950b57cec5SDimitry Andric bool operator()(const typename Predicate::argument_type& x) const; 1960b57cec5SDimitry Andric}; 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andrictemplate <class Predicate> // deprecated in C++17 1990b57cec5SDimitry Andricunary_negate<Predicate> not1(const Predicate& pred); 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andrictemplate <class Predicate> 2020b57cec5SDimitry Andricclass binary_negate // deprecated in C++17 2030b57cec5SDimitry Andric : public binary_function<typename Predicate::first_argument_type, 2040b57cec5SDimitry Andric typename Predicate::second_argument_type, 2050b57cec5SDimitry Andric bool> 2060b57cec5SDimitry Andric{ 2070b57cec5SDimitry Andricpublic: 2080b57cec5SDimitry Andric explicit binary_negate(const Predicate& pred); 2090b57cec5SDimitry Andric bool operator()(const typename Predicate::first_argument_type& x, 2100b57cec5SDimitry Andric const typename Predicate::second_argument_type& y) const; 2110b57cec5SDimitry Andric}; 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andrictemplate <class Predicate> // deprecated in C++17 2140b57cec5SDimitry Andricbinary_negate<Predicate> not2(const Predicate& pred); 2150b57cec5SDimitry Andric 216*e8d8bef9SDimitry Andrictemplate <class F> 217*e8d8bef9SDimitry Andricconstexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andrictemplate<class T> struct is_bind_expression; 2200b57cec5SDimitry Andrictemplate<class T> struct is_placeholder; 2210b57cec5SDimitry Andric 2220b57cec5SDimitry Andric // See C++14 20.9.9, Function object binders 2230b57cec5SDimitry Andrictemplate <class T> inline constexpr bool is_bind_expression_v 2240b57cec5SDimitry Andric = is_bind_expression<T>::value; // C++17 2250b57cec5SDimitry Andrictemplate <class T> inline constexpr int is_placeholder_v 2260b57cec5SDimitry Andric = is_placeholder<T>::value; // C++17 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andrictemplate<class Fn, class... BoundArgs> 230*e8d8bef9SDimitry Andric constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 2310b57cec5SDimitry Andrictemplate<class R, class Fn, class... BoundArgs> 232*e8d8bef9SDimitry Andric constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 2330b57cec5SDimitry Andric 2340b57cec5SDimitry Andrictemplate<class F, class... Args> 235*e8d8bef9SDimitry Andric constexpr // constexpr in C++20 2360b57cec5SDimitry Andric invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17 2370b57cec5SDimitry Andric noexcept(is_nothrow_invocable_v<F, Args...>); 2380b57cec5SDimitry Andric 2390b57cec5SDimitry Andricnamespace placeholders { 2400b57cec5SDimitry Andric // M is the implementation-defined number of placeholders 2410b57cec5SDimitry Andric extern unspecified _1; 2420b57cec5SDimitry Andric extern unspecified _2; 2430b57cec5SDimitry Andric . 2440b57cec5SDimitry Andric . 2450b57cec5SDimitry Andric . 2460b57cec5SDimitry Andric extern unspecified _Mp; 2470b57cec5SDimitry Andric} 2480b57cec5SDimitry Andric 2490b57cec5SDimitry Andrictemplate <class Operation> 2500b57cec5SDimitry Andricclass binder1st // deprecated in C++11, removed in C++17 2510b57cec5SDimitry Andric : public unary_function<typename Operation::second_argument_type, 2520b57cec5SDimitry Andric typename Operation::result_type> 2530b57cec5SDimitry Andric{ 2540b57cec5SDimitry Andricprotected: 2550b57cec5SDimitry Andric Operation op; 2560b57cec5SDimitry Andric typename Operation::first_argument_type value; 2570b57cec5SDimitry Andricpublic: 2580b57cec5SDimitry Andric binder1st(const Operation& x, const typename Operation::first_argument_type y); 2590b57cec5SDimitry Andric typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; 2600b57cec5SDimitry Andric typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; 2610b57cec5SDimitry Andric}; 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andrictemplate <class Operation, class T> 2640b57cec5SDimitry Andricbinder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andrictemplate <class Operation> 2670b57cec5SDimitry Andricclass binder2nd // deprecated in C++11, removed in C++17 2680b57cec5SDimitry Andric : public unary_function<typename Operation::first_argument_type, 2690b57cec5SDimitry Andric typename Operation::result_type> 2700b57cec5SDimitry Andric{ 2710b57cec5SDimitry Andricprotected: 2720b57cec5SDimitry Andric Operation op; 2730b57cec5SDimitry Andric typename Operation::second_argument_type value; 2740b57cec5SDimitry Andricpublic: 2750b57cec5SDimitry Andric binder2nd(const Operation& x, const typename Operation::second_argument_type y); 2760b57cec5SDimitry Andric typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; 2770b57cec5SDimitry Andric typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; 2780b57cec5SDimitry Andric}; 2790b57cec5SDimitry Andric 2800b57cec5SDimitry Andrictemplate <class Operation, class T> 2810b57cec5SDimitry Andricbinder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andrictemplate <class Arg, class Result> // deprecated in C++11, removed in C++17 2840b57cec5SDimitry Andricclass pointer_to_unary_function : public unary_function<Arg, Result> 2850b57cec5SDimitry Andric{ 2860b57cec5SDimitry Andricpublic: 2870b57cec5SDimitry Andric explicit pointer_to_unary_function(Result (*f)(Arg)); 2880b57cec5SDimitry Andric Result operator()(Arg x) const; 2890b57cec5SDimitry Andric}; 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andrictemplate <class Arg, class Result> 2920b57cec5SDimitry Andricpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 2950b57cec5SDimitry Andricclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 2960b57cec5SDimitry Andric{ 2970b57cec5SDimitry Andricpublic: 2980b57cec5SDimitry Andric explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 2990b57cec5SDimitry Andric Result operator()(Arg1 x, Arg2 y) const; 3000b57cec5SDimitry Andric}; 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> 3030b57cec5SDimitry Andricpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andrictemplate<class S, class T> // deprecated in C++11, removed in C++17 3060b57cec5SDimitry Andricclass mem_fun_t : public unary_function<T*, S> 3070b57cec5SDimitry Andric{ 3080b57cec5SDimitry Andricpublic: 3090b57cec5SDimitry Andric explicit mem_fun_t(S (T::*p)()); 3100b57cec5SDimitry Andric S operator()(T* p) const; 3110b57cec5SDimitry Andric}; 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andrictemplate<class S, class T, class A> 3140b57cec5SDimitry Andricclass mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 3150b57cec5SDimitry Andric{ 3160b57cec5SDimitry Andricpublic: 3170b57cec5SDimitry Andric explicit mem_fun1_t(S (T::*p)(A)); 3180b57cec5SDimitry Andric S operator()(T* p, A x) const; 3190b57cec5SDimitry Andric}; 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andrictemplate<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 3220b57cec5SDimitry Andrictemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andrictemplate<class S, class T> 3250b57cec5SDimitry Andricclass mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3260b57cec5SDimitry Andric{ 3270b57cec5SDimitry Andricpublic: 3280b57cec5SDimitry Andric explicit mem_fun_ref_t(S (T::*p)()); 3290b57cec5SDimitry Andric S operator()(T& p) const; 3300b57cec5SDimitry Andric}; 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andrictemplate<class S, class T, class A> 3330b57cec5SDimitry Andricclass mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3340b57cec5SDimitry Andric{ 3350b57cec5SDimitry Andricpublic: 3360b57cec5SDimitry Andric explicit mem_fun1_ref_t(S (T::*p)(A)); 3370b57cec5SDimitry Andric S operator()(T& p, A x) const; 3380b57cec5SDimitry Andric}; 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andrictemplate<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 3410b57cec5SDimitry Andrictemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andrictemplate <class S, class T> 3440b57cec5SDimitry Andricclass const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 3450b57cec5SDimitry Andric{ 3460b57cec5SDimitry Andricpublic: 3470b57cec5SDimitry Andric explicit const_mem_fun_t(S (T::*p)() const); 3480b57cec5SDimitry Andric S operator()(const T* p) const; 3490b57cec5SDimitry Andric}; 3500b57cec5SDimitry Andric 3510b57cec5SDimitry Andrictemplate <class S, class T, class A> 3520b57cec5SDimitry Andricclass const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 3530b57cec5SDimitry Andric{ 3540b57cec5SDimitry Andricpublic: 3550b57cec5SDimitry Andric explicit const_mem_fun1_t(S (T::*p)(A) const); 3560b57cec5SDimitry Andric S operator()(const T* p, A x) const; 3570b57cec5SDimitry Andric}; 3580b57cec5SDimitry Andric 3590b57cec5SDimitry Andrictemplate <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 3600b57cec5SDimitry Andrictemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3610b57cec5SDimitry Andric 3620b57cec5SDimitry Andrictemplate <class S, class T> 3630b57cec5SDimitry Andricclass const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3640b57cec5SDimitry Andric{ 3650b57cec5SDimitry Andricpublic: 3660b57cec5SDimitry Andric explicit const_mem_fun_ref_t(S (T::*p)() const); 3670b57cec5SDimitry Andric S operator()(const T& p) const; 3680b57cec5SDimitry Andric}; 3690b57cec5SDimitry Andric 3700b57cec5SDimitry Andrictemplate <class S, class T, class A> 3710b57cec5SDimitry Andricclass const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3720b57cec5SDimitry Andric{ 3730b57cec5SDimitry Andricpublic: 3740b57cec5SDimitry Andric explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 3750b57cec5SDimitry Andric S operator()(const T& p, A x) const; 3760b57cec5SDimitry Andric}; 3770b57cec5SDimitry Andric 3780b57cec5SDimitry Andrictemplate <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 3790b57cec5SDimitry Andrictemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3800b57cec5SDimitry Andric 381*e8d8bef9SDimitry Andrictemplate<class R, class T> 382*e8d8bef9SDimitry Andricconstexpr unspecified mem_fn(R T::*); // constexpr in C++20 3830b57cec5SDimitry Andric 3840b57cec5SDimitry Andricclass bad_function_call 3850b57cec5SDimitry Andric : public exception 3860b57cec5SDimitry Andric{ 3870b57cec5SDimitry Andric}; 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andrictemplate<class> class function; // undefined 3900b57cec5SDimitry Andric 3910b57cec5SDimitry Andrictemplate<class R, class... ArgTypes> 3920b57cec5SDimitry Andricclass function<R(ArgTypes...)> 3930b57cec5SDimitry Andric : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and 3940b57cec5SDimitry Andric // ArgTypes contains T1 3950b57cec5SDimitry Andric : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and 3960b57cec5SDimitry Andric // ArgTypes contains T1 and T2 3970b57cec5SDimitry Andric{ 3980b57cec5SDimitry Andricpublic: 3990b57cec5SDimitry Andric typedef R result_type; 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andric // construct/copy/destroy: 4020b57cec5SDimitry Andric function() noexcept; 4030b57cec5SDimitry Andric function(nullptr_t) noexcept; 4040b57cec5SDimitry Andric function(const function&); 4050b57cec5SDimitry Andric function(function&&) noexcept; 4060b57cec5SDimitry Andric template<class F> 4070b57cec5SDimitry Andric function(F); 4080b57cec5SDimitry Andric template<Allocator Alloc> 4090b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 4100b57cec5SDimitry Andric template<Allocator Alloc> 4110b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 4120b57cec5SDimitry Andric template<Allocator Alloc> 4130b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 4140b57cec5SDimitry Andric template<Allocator Alloc> 4150b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 4160b57cec5SDimitry Andric template<class F, Allocator Alloc> 4170b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, F); // removed in C++17 4180b57cec5SDimitry Andric 4190b57cec5SDimitry Andric function& operator=(const function&); 4200b57cec5SDimitry Andric function& operator=(function&&) noexcept; 4210b57cec5SDimitry Andric function& operator=(nullptr_t) noexcept; 4220b57cec5SDimitry Andric template<class F> 4230b57cec5SDimitry Andric function& operator=(F&&); 4240b57cec5SDimitry Andric template<class F> 4250b57cec5SDimitry Andric function& operator=(reference_wrapper<F>) noexcept; 4260b57cec5SDimitry Andric 4270b57cec5SDimitry Andric ~function(); 4280b57cec5SDimitry Andric 4290b57cec5SDimitry Andric // function modifiers: 4300b57cec5SDimitry Andric void swap(function&) noexcept; 4310b57cec5SDimitry Andric template<class F, class Alloc> 4320b57cec5SDimitry Andric void assign(F&&, const Alloc&); // Removed in C++17 4330b57cec5SDimitry Andric 4340b57cec5SDimitry Andric // function capacity: 4350b57cec5SDimitry Andric explicit operator bool() const noexcept; 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric // function invocation: 4380b57cec5SDimitry Andric R operator()(ArgTypes...) const; 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric // function target access: 4410b57cec5SDimitry Andric const std::type_info& target_type() const noexcept; 4420b57cec5SDimitry Andric template <typename T> T* target() noexcept; 4430b57cec5SDimitry Andric template <typename T> const T* target() const noexcept; 4440b57cec5SDimitry Andric}; 4450b57cec5SDimitry Andric 446e40139ffSDimitry Andric// Deduction guides 447e40139ffSDimitry Andrictemplate<class R, class ...Args> 448e40139ffSDimitry Andricfunction(R(*)(Args...)) -> function<R(Args...)>; // since C++17 449e40139ffSDimitry Andric 450e40139ffSDimitry Andrictemplate<class F> 451e40139ffSDimitry Andricfunction(F) -> function<see-below>; // since C++17 452e40139ffSDimitry Andric 4530b57cec5SDimitry Andric// Null pointer comparisons: 4540b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4550b57cec5SDimitry Andric bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4580b57cec5SDimitry Andric bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4590b57cec5SDimitry Andric 4600b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4610b57cec5SDimitry Andric bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4620b57cec5SDimitry Andric 4630b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4640b57cec5SDimitry Andric bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4650b57cec5SDimitry Andric 4660b57cec5SDimitry Andric// specialized algorithms: 4670b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4680b57cec5SDimitry Andric void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 4690b57cec5SDimitry Andric 4700b57cec5SDimitry Andrictemplate <class T> struct hash; 4710b57cec5SDimitry Andric 4720b57cec5SDimitry Andrictemplate <> struct hash<bool>; 4730b57cec5SDimitry Andrictemplate <> struct hash<char>; 4740b57cec5SDimitry Andrictemplate <> struct hash<signed char>; 4750b57cec5SDimitry Andrictemplate <> struct hash<unsigned char>; 476*e8d8bef9SDimitry Andrictemplate <> struct hash<char8_t>; // since C++20 4770b57cec5SDimitry Andrictemplate <> struct hash<char16_t>; 4780b57cec5SDimitry Andrictemplate <> struct hash<char32_t>; 4790b57cec5SDimitry Andrictemplate <> struct hash<wchar_t>; 4800b57cec5SDimitry Andrictemplate <> struct hash<short>; 4810b57cec5SDimitry Andrictemplate <> struct hash<unsigned short>; 4820b57cec5SDimitry Andrictemplate <> struct hash<int>; 4830b57cec5SDimitry Andrictemplate <> struct hash<unsigned int>; 4840b57cec5SDimitry Andrictemplate <> struct hash<long>; 4850b57cec5SDimitry Andrictemplate <> struct hash<long long>; 4860b57cec5SDimitry Andrictemplate <> struct hash<unsigned long>; 4870b57cec5SDimitry Andrictemplate <> struct hash<unsigned long long>; 4880b57cec5SDimitry Andric 4890b57cec5SDimitry Andrictemplate <> struct hash<float>; 4900b57cec5SDimitry Andrictemplate <> struct hash<double>; 4910b57cec5SDimitry Andrictemplate <> struct hash<long double>; 4920b57cec5SDimitry Andric 4930b57cec5SDimitry Andrictemplate<class T> struct hash<T*>; 4940b57cec5SDimitry Andrictemplate <> struct hash<nullptr_t>; // C++17 4950b57cec5SDimitry Andric 4960b57cec5SDimitry Andric} // std 4970b57cec5SDimitry Andric 4980b57cec5SDimitry AndricPOLICY: For non-variadic implementations, the number of arguments is limited 4990b57cec5SDimitry Andric to 3. It is hoped that the need for non-variadic implementations 5000b57cec5SDimitry Andric will be minimal. 5010b57cec5SDimitry Andric 5020b57cec5SDimitry Andric*/ 5030b57cec5SDimitry Andric 5040b57cec5SDimitry Andric#include <__config> 5050b57cec5SDimitry Andric#include <type_traits> 5060b57cec5SDimitry Andric#include <typeinfo> 5070b57cec5SDimitry Andric#include <exception> 5080b57cec5SDimitry Andric#include <memory> 5090b57cec5SDimitry Andric#include <tuple> 5100b57cec5SDimitry Andric#include <utility> 5110b57cec5SDimitry Andric#include <version> 5120b57cec5SDimitry Andric 5130b57cec5SDimitry Andric#include <__functional_base> 5140b57cec5SDimitry Andric 5150b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 5160b57cec5SDimitry Andric#pragma GCC system_header 5170b57cec5SDimitry Andric#endif 5180b57cec5SDimitry Andric 5190b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 5200b57cec5SDimitry Andric 5210b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 5220b57cec5SDimitry Andrictemplate <class _Tp = void> 5230b57cec5SDimitry Andric#else 5240b57cec5SDimitry Andrictemplate <class _Tp> 5250b57cec5SDimitry Andric#endif 5260b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp> 5270b57cec5SDimitry Andric{ 5280b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5290b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 5300b57cec5SDimitry Andric {return __x + __y;} 5310b57cec5SDimitry Andric}; 5320b57cec5SDimitry Andric 5330b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 5340b57cec5SDimitry Andrictemplate <> 5350b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS plus<void> 5360b57cec5SDimitry Andric{ 5370b57cec5SDimitry Andric template <class _T1, class _T2> 5380b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5390b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 5400b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) 5410b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) 5420b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 5430b57cec5SDimitry Andric typedef void is_transparent; 5440b57cec5SDimitry Andric}; 5450b57cec5SDimitry Andric#endif 5460b57cec5SDimitry Andric 5470b57cec5SDimitry Andric 5480b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 5490b57cec5SDimitry Andrictemplate <class _Tp = void> 5500b57cec5SDimitry Andric#else 5510b57cec5SDimitry Andrictemplate <class _Tp> 5520b57cec5SDimitry Andric#endif 5530b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp> 5540b57cec5SDimitry Andric{ 5550b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5560b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 5570b57cec5SDimitry Andric {return __x - __y;} 5580b57cec5SDimitry Andric}; 5590b57cec5SDimitry Andric 5600b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 5610b57cec5SDimitry Andrictemplate <> 5620b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS minus<void> 5630b57cec5SDimitry Andric{ 5640b57cec5SDimitry Andric template <class _T1, class _T2> 5650b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5660b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 5670b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) 5680b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) 5690b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } 5700b57cec5SDimitry Andric typedef void is_transparent; 5710b57cec5SDimitry Andric}; 5720b57cec5SDimitry Andric#endif 5730b57cec5SDimitry Andric 5740b57cec5SDimitry Andric 5750b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 5760b57cec5SDimitry Andrictemplate <class _Tp = void> 5770b57cec5SDimitry Andric#else 5780b57cec5SDimitry Andrictemplate <class _Tp> 5790b57cec5SDimitry Andric#endif 5800b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> 5810b57cec5SDimitry Andric{ 5820b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5830b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 5840b57cec5SDimitry Andric {return __x * __y;} 5850b57cec5SDimitry Andric}; 5860b57cec5SDimitry Andric 5870b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 5880b57cec5SDimitry Andrictemplate <> 5890b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS multiplies<void> 5900b57cec5SDimitry Andric{ 5910b57cec5SDimitry Andric template <class _T1, class _T2> 5920b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5930b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 5940b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) 5950b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) 5960b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } 5970b57cec5SDimitry Andric typedef void is_transparent; 5980b57cec5SDimitry Andric}; 5990b57cec5SDimitry Andric#endif 6000b57cec5SDimitry Andric 6010b57cec5SDimitry Andric 6020b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6030b57cec5SDimitry Andrictemplate <class _Tp = void> 6040b57cec5SDimitry Andric#else 6050b57cec5SDimitry Andrictemplate <class _Tp> 6060b57cec5SDimitry Andric#endif 6070b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp> 6080b57cec5SDimitry Andric{ 6090b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6100b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 6110b57cec5SDimitry Andric {return __x / __y;} 6120b57cec5SDimitry Andric}; 6130b57cec5SDimitry Andric 6140b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6150b57cec5SDimitry Andrictemplate <> 6160b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS divides<void> 6170b57cec5SDimitry Andric{ 6180b57cec5SDimitry Andric template <class _T1, class _T2> 6190b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6200b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 6210b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) 6220b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) 6230b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } 6240b57cec5SDimitry Andric typedef void is_transparent; 6250b57cec5SDimitry Andric}; 6260b57cec5SDimitry Andric#endif 6270b57cec5SDimitry Andric 6280b57cec5SDimitry Andric 6290b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6300b57cec5SDimitry Andrictemplate <class _Tp = void> 6310b57cec5SDimitry Andric#else 6320b57cec5SDimitry Andrictemplate <class _Tp> 6330b57cec5SDimitry Andric#endif 6340b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp> 6350b57cec5SDimitry Andric{ 6360b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6370b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 6380b57cec5SDimitry Andric {return __x % __y;} 6390b57cec5SDimitry Andric}; 6400b57cec5SDimitry Andric 6410b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6420b57cec5SDimitry Andrictemplate <> 6430b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS modulus<void> 6440b57cec5SDimitry Andric{ 6450b57cec5SDimitry Andric template <class _T1, class _T2> 6460b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6470b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 6480b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) 6490b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) 6500b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } 6510b57cec5SDimitry Andric typedef void is_transparent; 6520b57cec5SDimitry Andric}; 6530b57cec5SDimitry Andric#endif 6540b57cec5SDimitry Andric 6550b57cec5SDimitry Andric 6560b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6570b57cec5SDimitry Andrictemplate <class _Tp = void> 6580b57cec5SDimitry Andric#else 6590b57cec5SDimitry Andrictemplate <class _Tp> 6600b57cec5SDimitry Andric#endif 6610b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp> 6620b57cec5SDimitry Andric{ 6630b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6640b57cec5SDimitry Andric _Tp operator()(const _Tp& __x) const 6650b57cec5SDimitry Andric {return -__x;} 6660b57cec5SDimitry Andric}; 6670b57cec5SDimitry Andric 6680b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6690b57cec5SDimitry Andrictemplate <> 6700b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS negate<void> 6710b57cec5SDimitry Andric{ 6720b57cec5SDimitry Andric template <class _Tp> 6730b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6740b57cec5SDimitry Andric auto operator()(_Tp&& __x) const 6750b57cec5SDimitry Andric _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) 6760b57cec5SDimitry Andric -> decltype (- _VSTD::forward<_Tp>(__x)) 6770b57cec5SDimitry Andric { return - _VSTD::forward<_Tp>(__x); } 6780b57cec5SDimitry Andric typedef void is_transparent; 6790b57cec5SDimitry Andric}; 6800b57cec5SDimitry Andric#endif 6810b57cec5SDimitry Andric 6820b57cec5SDimitry Andric 6830b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6840b57cec5SDimitry Andrictemplate <class _Tp = void> 6850b57cec5SDimitry Andric#else 6860b57cec5SDimitry Andrictemplate <class _Tp> 6870b57cec5SDimitry Andric#endif 6880b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool> 6890b57cec5SDimitry Andric{ 6900b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6910b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 6920b57cec5SDimitry Andric {return __x == __y;} 6930b57cec5SDimitry Andric}; 6940b57cec5SDimitry Andric 6950b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 6960b57cec5SDimitry Andrictemplate <> 6970b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS equal_to<void> 6980b57cec5SDimitry Andric{ 6990b57cec5SDimitry Andric template <class _T1, class _T2> 7000b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7010b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 7020b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) 7030b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) 7040b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } 7050b57cec5SDimitry Andric typedef void is_transparent; 7060b57cec5SDimitry Andric}; 7070b57cec5SDimitry Andric#endif 7080b57cec5SDimitry Andric 7090b57cec5SDimitry Andric 7100b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 7110b57cec5SDimitry Andrictemplate <class _Tp = void> 7120b57cec5SDimitry Andric#else 7130b57cec5SDimitry Andrictemplate <class _Tp> 7140b57cec5SDimitry Andric#endif 7150b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> 7160b57cec5SDimitry Andric{ 7170b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7180b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 7190b57cec5SDimitry Andric {return __x != __y;} 7200b57cec5SDimitry Andric}; 7210b57cec5SDimitry Andric 7220b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 7230b57cec5SDimitry Andrictemplate <> 7240b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS not_equal_to<void> 7250b57cec5SDimitry Andric{ 7260b57cec5SDimitry Andric template <class _T1, class _T2> 7270b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7280b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 7290b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) 7300b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) 7310b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } 7320b57cec5SDimitry Andric typedef void is_transparent; 7330b57cec5SDimitry Andric}; 7340b57cec5SDimitry Andric#endif 7350b57cec5SDimitry Andric 7360b57cec5SDimitry Andric 7370b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 7380b57cec5SDimitry Andrictemplate <class _Tp = void> 7390b57cec5SDimitry Andric#else 7400b57cec5SDimitry Andrictemplate <class _Tp> 7410b57cec5SDimitry Andric#endif 7420b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool> 7430b57cec5SDimitry Andric{ 7440b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7450b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 7460b57cec5SDimitry Andric {return __x > __y;} 7470b57cec5SDimitry Andric}; 7480b57cec5SDimitry Andric 7490b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 7500b57cec5SDimitry Andrictemplate <> 7510b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS greater<void> 7520b57cec5SDimitry Andric{ 7530b57cec5SDimitry Andric template <class _T1, class _T2> 7540b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7550b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 7560b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) 7570b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) 7580b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } 7590b57cec5SDimitry Andric typedef void is_transparent; 7600b57cec5SDimitry Andric}; 7610b57cec5SDimitry Andric#endif 7620b57cec5SDimitry Andric 7630b57cec5SDimitry Andric 7640b57cec5SDimitry Andric// less in <__functional_base> 7650b57cec5SDimitry Andric 7660b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 7670b57cec5SDimitry Andrictemplate <class _Tp = void> 7680b57cec5SDimitry Andric#else 7690b57cec5SDimitry Andrictemplate <class _Tp> 7700b57cec5SDimitry Andric#endif 7710b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool> 7720b57cec5SDimitry Andric{ 7730b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7740b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 7750b57cec5SDimitry Andric {return __x >= __y;} 7760b57cec5SDimitry Andric}; 7770b57cec5SDimitry Andric 7780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 7790b57cec5SDimitry Andrictemplate <> 7800b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS greater_equal<void> 7810b57cec5SDimitry Andric{ 7820b57cec5SDimitry Andric template <class _T1, class _T2> 7830b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7840b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 7850b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) 7860b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) 7870b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } 7880b57cec5SDimitry Andric typedef void is_transparent; 7890b57cec5SDimitry Andric}; 7900b57cec5SDimitry Andric#endif 7910b57cec5SDimitry Andric 7920b57cec5SDimitry Andric 7930b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 7940b57cec5SDimitry Andrictemplate <class _Tp = void> 7950b57cec5SDimitry Andric#else 7960b57cec5SDimitry Andrictemplate <class _Tp> 7970b57cec5SDimitry Andric#endif 7980b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool> 7990b57cec5SDimitry Andric{ 8000b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8010b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 8020b57cec5SDimitry Andric {return __x <= __y;} 8030b57cec5SDimitry Andric}; 8040b57cec5SDimitry Andric 8050b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8060b57cec5SDimitry Andrictemplate <> 8070b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS less_equal<void> 8080b57cec5SDimitry Andric{ 8090b57cec5SDimitry Andric template <class _T1, class _T2> 8100b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8110b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 8120b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) 8130b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) 8140b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } 8150b57cec5SDimitry Andric typedef void is_transparent; 8160b57cec5SDimitry Andric}; 8170b57cec5SDimitry Andric#endif 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andric 8200b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8210b57cec5SDimitry Andrictemplate <class _Tp = void> 8220b57cec5SDimitry Andric#else 8230b57cec5SDimitry Andrictemplate <class _Tp> 8240b57cec5SDimitry Andric#endif 8250b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool> 8260b57cec5SDimitry Andric{ 8270b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8280b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 8290b57cec5SDimitry Andric {return __x && __y;} 8300b57cec5SDimitry Andric}; 8310b57cec5SDimitry Andric 8320b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8330b57cec5SDimitry Andrictemplate <> 8340b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS logical_and<void> 8350b57cec5SDimitry Andric{ 8360b57cec5SDimitry Andric template <class _T1, class _T2> 8370b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8380b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 8390b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) 8400b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) 8410b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } 8420b57cec5SDimitry Andric typedef void is_transparent; 8430b57cec5SDimitry Andric}; 8440b57cec5SDimitry Andric#endif 8450b57cec5SDimitry Andric 8460b57cec5SDimitry Andric 8470b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8480b57cec5SDimitry Andrictemplate <class _Tp = void> 8490b57cec5SDimitry Andric#else 8500b57cec5SDimitry Andrictemplate <class _Tp> 8510b57cec5SDimitry Andric#endif 8520b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool> 8530b57cec5SDimitry Andric{ 8540b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8550b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Tp& __y) const 8560b57cec5SDimitry Andric {return __x || __y;} 8570b57cec5SDimitry Andric}; 8580b57cec5SDimitry Andric 8590b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8600b57cec5SDimitry Andrictemplate <> 8610b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS logical_or<void> 8620b57cec5SDimitry Andric{ 8630b57cec5SDimitry Andric template <class _T1, class _T2> 8640b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8650b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 8660b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) 8670b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) 8680b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } 8690b57cec5SDimitry Andric typedef void is_transparent; 8700b57cec5SDimitry Andric}; 8710b57cec5SDimitry Andric#endif 8720b57cec5SDimitry Andric 8730b57cec5SDimitry Andric 8740b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8750b57cec5SDimitry Andrictemplate <class _Tp = void> 8760b57cec5SDimitry Andric#else 8770b57cec5SDimitry Andrictemplate <class _Tp> 8780b57cec5SDimitry Andric#endif 8790b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool> 8800b57cec5SDimitry Andric{ 8810b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8820b57cec5SDimitry Andric bool operator()(const _Tp& __x) const 8830b57cec5SDimitry Andric {return !__x;} 8840b57cec5SDimitry Andric}; 8850b57cec5SDimitry Andric 8860b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8870b57cec5SDimitry Andrictemplate <> 8880b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS logical_not<void> 8890b57cec5SDimitry Andric{ 8900b57cec5SDimitry Andric template <class _Tp> 8910b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8920b57cec5SDimitry Andric auto operator()(_Tp&& __x) const 8930b57cec5SDimitry Andric _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) 8940b57cec5SDimitry Andric -> decltype (!_VSTD::forward<_Tp>(__x)) 8950b57cec5SDimitry Andric { return !_VSTD::forward<_Tp>(__x); } 8960b57cec5SDimitry Andric typedef void is_transparent; 8970b57cec5SDimitry Andric}; 8980b57cec5SDimitry Andric#endif 8990b57cec5SDimitry Andric 9000b57cec5SDimitry Andric 9010b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9020b57cec5SDimitry Andrictemplate <class _Tp = void> 9030b57cec5SDimitry Andric#else 9040b57cec5SDimitry Andrictemplate <class _Tp> 9050b57cec5SDimitry Andric#endif 9060b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> 9070b57cec5SDimitry Andric{ 9080b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9090b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 9100b57cec5SDimitry Andric {return __x & __y;} 9110b57cec5SDimitry Andric}; 9120b57cec5SDimitry Andric 9130b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9140b57cec5SDimitry Andrictemplate <> 9150b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_and<void> 9160b57cec5SDimitry Andric{ 9170b57cec5SDimitry Andric template <class _T1, class _T2> 9180b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9190b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 9200b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) 9210b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) 9220b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } 9230b57cec5SDimitry Andric typedef void is_transparent; 9240b57cec5SDimitry Andric}; 9250b57cec5SDimitry Andric#endif 9260b57cec5SDimitry Andric 9270b57cec5SDimitry Andric 9280b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9290b57cec5SDimitry Andrictemplate <class _Tp = void> 9300b57cec5SDimitry Andric#else 9310b57cec5SDimitry Andrictemplate <class _Tp> 9320b57cec5SDimitry Andric#endif 9330b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> 9340b57cec5SDimitry Andric{ 9350b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9360b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 9370b57cec5SDimitry Andric {return __x | __y;} 9380b57cec5SDimitry Andric}; 9390b57cec5SDimitry Andric 9400b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9410b57cec5SDimitry Andrictemplate <> 9420b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_or<void> 9430b57cec5SDimitry Andric{ 9440b57cec5SDimitry Andric template <class _T1, class _T2> 9450b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9460b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 9470b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) 9480b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) 9490b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } 9500b57cec5SDimitry Andric typedef void is_transparent; 9510b57cec5SDimitry Andric}; 9520b57cec5SDimitry Andric#endif 9530b57cec5SDimitry Andric 9540b57cec5SDimitry Andric 9550b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9560b57cec5SDimitry Andrictemplate <class _Tp = void> 9570b57cec5SDimitry Andric#else 9580b57cec5SDimitry Andrictemplate <class _Tp> 9590b57cec5SDimitry Andric#endif 9600b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> 9610b57cec5SDimitry Andric{ 9620b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9630b57cec5SDimitry Andric _Tp operator()(const _Tp& __x, const _Tp& __y) const 9640b57cec5SDimitry Andric {return __x ^ __y;} 9650b57cec5SDimitry Andric}; 9660b57cec5SDimitry Andric 9670b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9680b57cec5SDimitry Andrictemplate <> 9690b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_xor<void> 9700b57cec5SDimitry Andric{ 9710b57cec5SDimitry Andric template <class _T1, class _T2> 9720b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9730b57cec5SDimitry Andric auto operator()(_T1&& __t, _T2&& __u) const 9740b57cec5SDimitry Andric _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) 9750b57cec5SDimitry Andric -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) 9760b57cec5SDimitry Andric { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } 9770b57cec5SDimitry Andric typedef void is_transparent; 9780b57cec5SDimitry Andric}; 9790b57cec5SDimitry Andric#endif 9800b57cec5SDimitry Andric 9810b57cec5SDimitry Andric 9820b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9830b57cec5SDimitry Andrictemplate <class _Tp = void> 9840b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp> 9850b57cec5SDimitry Andric{ 9860b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9870b57cec5SDimitry Andric _Tp operator()(const _Tp& __x) const 9880b57cec5SDimitry Andric {return ~__x;} 9890b57cec5SDimitry Andric}; 9900b57cec5SDimitry Andric 9910b57cec5SDimitry Andrictemplate <> 9920b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bit_not<void> 9930b57cec5SDimitry Andric{ 9940b57cec5SDimitry Andric template <class _Tp> 9950b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9960b57cec5SDimitry Andric auto operator()(_Tp&& __x) const 9970b57cec5SDimitry Andric _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) 9980b57cec5SDimitry Andric -> decltype (~_VSTD::forward<_Tp>(__x)) 9990b57cec5SDimitry Andric { return ~_VSTD::forward<_Tp>(__x); } 10000b57cec5SDimitry Andric typedef void is_transparent; 10010b57cec5SDimitry Andric}; 10020b57cec5SDimitry Andric#endif 10030b57cec5SDimitry Andric 10040b57cec5SDimitry Andrictemplate <class _Predicate> 10050b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate 10060b57cec5SDimitry Andric : public unary_function<typename _Predicate::argument_type, bool> 10070b57cec5SDimitry Andric{ 10080b57cec5SDimitry Andric _Predicate __pred_; 10090b57cec5SDimitry Andricpublic: 10100b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10110b57cec5SDimitry Andric explicit unary_negate(const _Predicate& __pred) 10120b57cec5SDimitry Andric : __pred_(__pred) {} 10130b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10140b57cec5SDimitry Andric bool operator()(const typename _Predicate::argument_type& __x) const 10150b57cec5SDimitry Andric {return !__pred_(__x);} 10160b57cec5SDimitry Andric}; 10170b57cec5SDimitry Andric 10180b57cec5SDimitry Andrictemplate <class _Predicate> 10190b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10200b57cec5SDimitry Andricunary_negate<_Predicate> 10210b57cec5SDimitry Andricnot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} 10220b57cec5SDimitry Andric 10230b57cec5SDimitry Andrictemplate <class _Predicate> 10240b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate 10250b57cec5SDimitry Andric : public binary_function<typename _Predicate::first_argument_type, 10260b57cec5SDimitry Andric typename _Predicate::second_argument_type, 10270b57cec5SDimitry Andric bool> 10280b57cec5SDimitry Andric{ 10290b57cec5SDimitry Andric _Predicate __pred_; 10300b57cec5SDimitry Andricpublic: 10310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 10320b57cec5SDimitry Andric binary_negate(const _Predicate& __pred) : __pred_(__pred) {} 10330b57cec5SDimitry Andric 10340b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10350b57cec5SDimitry Andric bool operator()(const typename _Predicate::first_argument_type& __x, 10360b57cec5SDimitry Andric const typename _Predicate::second_argument_type& __y) const 10370b57cec5SDimitry Andric {return !__pred_(__x, __y);} 10380b57cec5SDimitry Andric}; 10390b57cec5SDimitry Andric 10400b57cec5SDimitry Andrictemplate <class _Predicate> 10410b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10420b57cec5SDimitry Andricbinary_negate<_Predicate> 10430b57cec5SDimitry Andricnot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} 10440b57cec5SDimitry Andric 10450b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) 10460b57cec5SDimitry Andrictemplate <class __Operation> 10470b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st 10480b57cec5SDimitry Andric : public unary_function<typename __Operation::second_argument_type, 10490b57cec5SDimitry Andric typename __Operation::result_type> 10500b57cec5SDimitry Andric{ 10510b57cec5SDimitry Andricprotected: 10520b57cec5SDimitry Andric __Operation op; 10530b57cec5SDimitry Andric typename __Operation::first_argument_type value; 10540b57cec5SDimitry Andricpublic: 10550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, 10560b57cec5SDimitry Andric const typename __Operation::first_argument_type __y) 10570b57cec5SDimitry Andric : op(__x), value(__y) {} 10580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10590b57cec5SDimitry Andric (typename __Operation::second_argument_type& __x) const 10600b57cec5SDimitry Andric {return op(value, __x);} 10610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10620b57cec5SDimitry Andric (const typename __Operation::second_argument_type& __x) const 10630b57cec5SDimitry Andric {return op(value, __x);} 10640b57cec5SDimitry Andric}; 10650b57cec5SDimitry Andric 10660b57cec5SDimitry Andrictemplate <class __Operation, class _Tp> 10670b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 10680b57cec5SDimitry Andricbinder1st<__Operation> 10690b57cec5SDimitry Andricbind1st(const __Operation& __op, const _Tp& __x) 10700b57cec5SDimitry Andric {return binder1st<__Operation>(__op, __x);} 10710b57cec5SDimitry Andric 10720b57cec5SDimitry Andrictemplate <class __Operation> 10730b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd 10740b57cec5SDimitry Andric : public unary_function<typename __Operation::first_argument_type, 10750b57cec5SDimitry Andric typename __Operation::result_type> 10760b57cec5SDimitry Andric{ 10770b57cec5SDimitry Andricprotected: 10780b57cec5SDimitry Andric __Operation op; 10790b57cec5SDimitry Andric typename __Operation::second_argument_type value; 10800b57cec5SDimitry Andricpublic: 10810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10820b57cec5SDimitry Andric binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) 10830b57cec5SDimitry Andric : op(__x), value(__y) {} 10840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10850b57cec5SDimitry Andric ( typename __Operation::first_argument_type& __x) const 10860b57cec5SDimitry Andric {return op(__x, value);} 10870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10880b57cec5SDimitry Andric (const typename __Operation::first_argument_type& __x) const 10890b57cec5SDimitry Andric {return op(__x, value);} 10900b57cec5SDimitry Andric}; 10910b57cec5SDimitry Andric 10920b57cec5SDimitry Andrictemplate <class __Operation, class _Tp> 10930b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 10940b57cec5SDimitry Andricbinder2nd<__Operation> 10950b57cec5SDimitry Andricbind2nd(const __Operation& __op, const _Tp& __x) 10960b57cec5SDimitry Andric {return binder2nd<__Operation>(__op, __x);} 10970b57cec5SDimitry Andric 10980b57cec5SDimitry Andrictemplate <class _Arg, class _Result> 10990b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function 11000b57cec5SDimitry Andric : public unary_function<_Arg, _Result> 11010b57cec5SDimitry Andric{ 11020b57cec5SDimitry Andric _Result (*__f_)(_Arg); 11030b57cec5SDimitry Andricpublic: 11040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) 11050b57cec5SDimitry Andric : __f_(__f) {} 11060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const 11070b57cec5SDimitry Andric {return __f_(__x);} 11080b57cec5SDimitry Andric}; 11090b57cec5SDimitry Andric 11100b57cec5SDimitry Andrictemplate <class _Arg, class _Result> 11110b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11120b57cec5SDimitry Andricpointer_to_unary_function<_Arg,_Result> 11130b57cec5SDimitry Andricptr_fun(_Result (*__f)(_Arg)) 11140b57cec5SDimitry Andric {return pointer_to_unary_function<_Arg,_Result>(__f);} 11150b57cec5SDimitry Andric 11160b57cec5SDimitry Andrictemplate <class _Arg1, class _Arg2, class _Result> 11170b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function 11180b57cec5SDimitry Andric : public binary_function<_Arg1, _Arg2, _Result> 11190b57cec5SDimitry Andric{ 11200b57cec5SDimitry Andric _Result (*__f_)(_Arg1, _Arg2); 11210b57cec5SDimitry Andricpublic: 11220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) 11230b57cec5SDimitry Andric : __f_(__f) {} 11240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const 11250b57cec5SDimitry Andric {return __f_(__x, __y);} 11260b57cec5SDimitry Andric}; 11270b57cec5SDimitry Andric 11280b57cec5SDimitry Andrictemplate <class _Arg1, class _Arg2, class _Result> 11290b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11300b57cec5SDimitry Andricpointer_to_binary_function<_Arg1,_Arg2,_Result> 11310b57cec5SDimitry Andricptr_fun(_Result (*__f)(_Arg1,_Arg2)) 11320b57cec5SDimitry Andric {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} 11330b57cec5SDimitry Andric 11340b57cec5SDimitry Andrictemplate<class _Sp, class _Tp> 11350b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t 11360b57cec5SDimitry Andric : public unary_function<_Tp*, _Sp> 11370b57cec5SDimitry Andric{ 11380b57cec5SDimitry Andric _Sp (_Tp::*__p_)(); 11390b57cec5SDimitry Andricpublic: 11400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) 11410b57cec5SDimitry Andric : __p_(__p) {} 11420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const 11430b57cec5SDimitry Andric {return (__p->*__p_)();} 11440b57cec5SDimitry Andric}; 11450b57cec5SDimitry Andric 11460b57cec5SDimitry Andrictemplate<class _Sp, class _Tp, class _Ap> 11470b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t 11480b57cec5SDimitry Andric : public binary_function<_Tp*, _Ap, _Sp> 11490b57cec5SDimitry Andric{ 11500b57cec5SDimitry Andric _Sp (_Tp::*__p_)(_Ap); 11510b57cec5SDimitry Andricpublic: 11520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) 11530b57cec5SDimitry Andric : __p_(__p) {} 11540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const 11550b57cec5SDimitry Andric {return (__p->*__p_)(__x);} 11560b57cec5SDimitry Andric}; 11570b57cec5SDimitry Andric 11580b57cec5SDimitry Andrictemplate<class _Sp, class _Tp> 11590b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11600b57cec5SDimitry Andricmem_fun_t<_Sp,_Tp> 11610b57cec5SDimitry Andricmem_fun(_Sp (_Tp::*__f)()) 11620b57cec5SDimitry Andric {return mem_fun_t<_Sp,_Tp>(__f);} 11630b57cec5SDimitry Andric 11640b57cec5SDimitry Andrictemplate<class _Sp, class _Tp, class _Ap> 11650b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11660b57cec5SDimitry Andricmem_fun1_t<_Sp,_Tp,_Ap> 11670b57cec5SDimitry Andricmem_fun(_Sp (_Tp::*__f)(_Ap)) 11680b57cec5SDimitry Andric {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 11690b57cec5SDimitry Andric 11700b57cec5SDimitry Andrictemplate<class _Sp, class _Tp> 11710b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t 11720b57cec5SDimitry Andric : public unary_function<_Tp, _Sp> 11730b57cec5SDimitry Andric{ 11740b57cec5SDimitry Andric _Sp (_Tp::*__p_)(); 11750b57cec5SDimitry Andricpublic: 11760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) 11770b57cec5SDimitry Andric : __p_(__p) {} 11780b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const 11790b57cec5SDimitry Andric {return (__p.*__p_)();} 11800b57cec5SDimitry Andric}; 11810b57cec5SDimitry Andric 11820b57cec5SDimitry Andrictemplate<class _Sp, class _Tp, class _Ap> 11830b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t 11840b57cec5SDimitry Andric : public binary_function<_Tp, _Ap, _Sp> 11850b57cec5SDimitry Andric{ 11860b57cec5SDimitry Andric _Sp (_Tp::*__p_)(_Ap); 11870b57cec5SDimitry Andricpublic: 11880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) 11890b57cec5SDimitry Andric : __p_(__p) {} 11900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const 11910b57cec5SDimitry Andric {return (__p.*__p_)(__x);} 11920b57cec5SDimitry Andric}; 11930b57cec5SDimitry Andric 11940b57cec5SDimitry Andrictemplate<class _Sp, class _Tp> 11950b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11960b57cec5SDimitry Andricmem_fun_ref_t<_Sp,_Tp> 11970b57cec5SDimitry Andricmem_fun_ref(_Sp (_Tp::*__f)()) 11980b57cec5SDimitry Andric {return mem_fun_ref_t<_Sp,_Tp>(__f);} 11990b57cec5SDimitry Andric 12000b57cec5SDimitry Andrictemplate<class _Sp, class _Tp, class _Ap> 12010b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12020b57cec5SDimitry Andricmem_fun1_ref_t<_Sp,_Tp,_Ap> 12030b57cec5SDimitry Andricmem_fun_ref(_Sp (_Tp::*__f)(_Ap)) 12040b57cec5SDimitry Andric {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 12050b57cec5SDimitry Andric 12060b57cec5SDimitry Andrictemplate <class _Sp, class _Tp> 12070b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t 12080b57cec5SDimitry Andric : public unary_function<const _Tp*, _Sp> 12090b57cec5SDimitry Andric{ 12100b57cec5SDimitry Andric _Sp (_Tp::*__p_)() const; 12110b57cec5SDimitry Andricpublic: 12120b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) 12130b57cec5SDimitry Andric : __p_(__p) {} 12140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const 12150b57cec5SDimitry Andric {return (__p->*__p_)();} 12160b57cec5SDimitry Andric}; 12170b57cec5SDimitry Andric 12180b57cec5SDimitry Andrictemplate <class _Sp, class _Tp, class _Ap> 12190b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t 12200b57cec5SDimitry Andric : public binary_function<const _Tp*, _Ap, _Sp> 12210b57cec5SDimitry Andric{ 12220b57cec5SDimitry Andric _Sp (_Tp::*__p_)(_Ap) const; 12230b57cec5SDimitry Andricpublic: 12240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) 12250b57cec5SDimitry Andric : __p_(__p) {} 12260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const 12270b57cec5SDimitry Andric {return (__p->*__p_)(__x);} 12280b57cec5SDimitry Andric}; 12290b57cec5SDimitry Andric 12300b57cec5SDimitry Andrictemplate <class _Sp, class _Tp> 12310b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12320b57cec5SDimitry Andricconst_mem_fun_t<_Sp,_Tp> 12330b57cec5SDimitry Andricmem_fun(_Sp (_Tp::*__f)() const) 12340b57cec5SDimitry Andric {return const_mem_fun_t<_Sp,_Tp>(__f);} 12350b57cec5SDimitry Andric 12360b57cec5SDimitry Andrictemplate <class _Sp, class _Tp, class _Ap> 12370b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12380b57cec5SDimitry Andricconst_mem_fun1_t<_Sp,_Tp,_Ap> 12390b57cec5SDimitry Andricmem_fun(_Sp (_Tp::*__f)(_Ap) const) 12400b57cec5SDimitry Andric {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 12410b57cec5SDimitry Andric 12420b57cec5SDimitry Andrictemplate <class _Sp, class _Tp> 12430b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t 12440b57cec5SDimitry Andric : public unary_function<_Tp, _Sp> 12450b57cec5SDimitry Andric{ 12460b57cec5SDimitry Andric _Sp (_Tp::*__p_)() const; 12470b57cec5SDimitry Andricpublic: 12480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) 12490b57cec5SDimitry Andric : __p_(__p) {} 12500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const 12510b57cec5SDimitry Andric {return (__p.*__p_)();} 12520b57cec5SDimitry Andric}; 12530b57cec5SDimitry Andric 12540b57cec5SDimitry Andrictemplate <class _Sp, class _Tp, class _Ap> 12550b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t 12560b57cec5SDimitry Andric : public binary_function<_Tp, _Ap, _Sp> 12570b57cec5SDimitry Andric{ 12580b57cec5SDimitry Andric _Sp (_Tp::*__p_)(_Ap) const; 12590b57cec5SDimitry Andricpublic: 12600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) 12610b57cec5SDimitry Andric : __p_(__p) {} 12620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const 12630b57cec5SDimitry Andric {return (__p.*__p_)(__x);} 12640b57cec5SDimitry Andric}; 12650b57cec5SDimitry Andric 12660b57cec5SDimitry Andrictemplate <class _Sp, class _Tp> 12670b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12680b57cec5SDimitry Andricconst_mem_fun_ref_t<_Sp,_Tp> 12690b57cec5SDimitry Andricmem_fun_ref(_Sp (_Tp::*__f)() const) 12700b57cec5SDimitry Andric {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} 12710b57cec5SDimitry Andric 12720b57cec5SDimitry Andrictemplate <class _Sp, class _Tp, class _Ap> 12730b57cec5SDimitry Andric_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12740b57cec5SDimitry Andricconst_mem_fun1_ref_t<_Sp,_Tp,_Ap> 12750b57cec5SDimitry Andricmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) 12760b57cec5SDimitry Andric {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 12770b57cec5SDimitry Andric#endif 12780b57cec5SDimitry Andric 12790b57cec5SDimitry Andric//////////////////////////////////////////////////////////////////////////////// 12800b57cec5SDimitry Andric// MEMFUN 12810b57cec5SDimitry Andric//============================================================================== 12820b57cec5SDimitry Andric 12830b57cec5SDimitry Andrictemplate <class _Tp> 12840b57cec5SDimitry Andricclass __mem_fn 12850b57cec5SDimitry Andric : public __weak_result_type<_Tp> 12860b57cec5SDimitry Andric{ 12870b57cec5SDimitry Andricpublic: 12880b57cec5SDimitry Andric // types 12890b57cec5SDimitry Andric typedef _Tp type; 12900b57cec5SDimitry Andricprivate: 12910b57cec5SDimitry Andric type __f_; 12920b57cec5SDimitry Andric 12930b57cec5SDimitry Andricpublic: 1294*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 1295*e8d8bef9SDimitry Andric __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} 12960b57cec5SDimitry Andric 12970b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 12980b57cec5SDimitry Andric // invoke 12990b57cec5SDimitry Andric template <class... _ArgTypes> 1300*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 13010b57cec5SDimitry Andric typename __invoke_return<type, _ArgTypes...>::type 13020b57cec5SDimitry Andric operator() (_ArgTypes&&... __args) const { 1303*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); 13040b57cec5SDimitry Andric } 13050b57cec5SDimitry Andric#else 13060b57cec5SDimitry Andric 13070b57cec5SDimitry Andric template <class _A0> 13080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13090b57cec5SDimitry Andric typename __invoke_return0<type, _A0>::type 13100b57cec5SDimitry Andric operator() (_A0& __a0) const { 1311*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0); 13120b57cec5SDimitry Andric } 13130b57cec5SDimitry Andric 13140b57cec5SDimitry Andric template <class _A0> 13150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13160b57cec5SDimitry Andric typename __invoke_return0<type, _A0 const>::type 13170b57cec5SDimitry Andric operator() (_A0 const& __a0) const { 1318*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0); 13190b57cec5SDimitry Andric } 13200b57cec5SDimitry Andric 13210b57cec5SDimitry Andric template <class _A0, class _A1> 13220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13230b57cec5SDimitry Andric typename __invoke_return1<type, _A0, _A1>::type 13240b57cec5SDimitry Andric operator() (_A0& __a0, _A1& __a1) const { 1325*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1); 13260b57cec5SDimitry Andric } 13270b57cec5SDimitry Andric 13280b57cec5SDimitry Andric template <class _A0, class _A1> 13290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13300b57cec5SDimitry Andric typename __invoke_return1<type, _A0 const, _A1>::type 13310b57cec5SDimitry Andric operator() (_A0 const& __a0, _A1& __a1) const { 1332*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1); 13330b57cec5SDimitry Andric } 13340b57cec5SDimitry Andric 13350b57cec5SDimitry Andric template <class _A0, class _A1> 13360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13370b57cec5SDimitry Andric typename __invoke_return1<type, _A0, _A1 const>::type 13380b57cec5SDimitry Andric operator() (_A0& __a0, _A1 const& __a1) const { 1339*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1); 13400b57cec5SDimitry Andric } 13410b57cec5SDimitry Andric 13420b57cec5SDimitry Andric template <class _A0, class _A1> 13430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13440b57cec5SDimitry Andric typename __invoke_return1<type, _A0 const, _A1 const>::type 13450b57cec5SDimitry Andric operator() (_A0 const& __a0, _A1 const& __a1) const { 1346*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1); 13470b57cec5SDimitry Andric } 13480b57cec5SDimitry Andric 13490b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13510b57cec5SDimitry Andric typename __invoke_return2<type, _A0, _A1, _A2>::type 13520b57cec5SDimitry Andric operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { 1353*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 13540b57cec5SDimitry Andric } 13550b57cec5SDimitry Andric 13560b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13580b57cec5SDimitry Andric typename __invoke_return2<type, _A0 const, _A1, _A2>::type 13590b57cec5SDimitry Andric operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { 1360*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 13610b57cec5SDimitry Andric } 13620b57cec5SDimitry Andric 13630b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13650b57cec5SDimitry Andric typename __invoke_return2<type, _A0, _A1 const, _A2>::type 13660b57cec5SDimitry Andric operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { 1367*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 13680b57cec5SDimitry Andric } 13690b57cec5SDimitry Andric 13700b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13720b57cec5SDimitry Andric typename __invoke_return2<type, _A0, _A1, _A2 const>::type 13730b57cec5SDimitry Andric operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { 1374*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 13750b57cec5SDimitry Andric } 13760b57cec5SDimitry Andric 13770b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13780b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13790b57cec5SDimitry Andric typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type 13800b57cec5SDimitry Andric operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { 1381*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 13820b57cec5SDimitry Andric } 13830b57cec5SDimitry Andric 13840b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13850b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13860b57cec5SDimitry Andric typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type 13870b57cec5SDimitry Andric operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { 1388*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 13890b57cec5SDimitry Andric } 13900b57cec5SDimitry Andric 13910b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13930b57cec5SDimitry Andric typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type 13940b57cec5SDimitry Andric operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { 1395*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 13960b57cec5SDimitry Andric } 13970b57cec5SDimitry Andric 13980b57cec5SDimitry Andric template <class _A0, class _A1, class _A2> 13990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14000b57cec5SDimitry Andric typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type 14010b57cec5SDimitry Andric operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { 1402*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, __a0, __a1, __a2); 14030b57cec5SDimitry Andric } 14040b57cec5SDimitry Andric#endif 14050b57cec5SDimitry Andric}; 14060b57cec5SDimitry Andric 14070b57cec5SDimitry Andrictemplate<class _Rp, class _Tp> 1408*e8d8bef9SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 14090b57cec5SDimitry Andric__mem_fn<_Rp _Tp::*> 14100b57cec5SDimitry Andricmem_fn(_Rp _Tp::* __pm) _NOEXCEPT 14110b57cec5SDimitry Andric{ 14120b57cec5SDimitry Andric return __mem_fn<_Rp _Tp::*>(__pm); 14130b57cec5SDimitry Andric} 14140b57cec5SDimitry Andric 14150b57cec5SDimitry Andric//////////////////////////////////////////////////////////////////////////////// 14160b57cec5SDimitry Andric// FUNCTION 14170b57cec5SDimitry Andric//============================================================================== 14180b57cec5SDimitry Andric 14190b57cec5SDimitry Andric// bad_function_call 14200b57cec5SDimitry Andric 14210b57cec5SDimitry Andricclass _LIBCPP_EXCEPTION_ABI bad_function_call 14220b57cec5SDimitry Andric : public exception 14230b57cec5SDimitry Andric{ 14240b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 14250b57cec5SDimitry Andricpublic: 14260b57cec5SDimitry Andric virtual ~bad_function_call() _NOEXCEPT; 14270b57cec5SDimitry Andric 14280b57cec5SDimitry Andric virtual const char* what() const _NOEXCEPT; 14290b57cec5SDimitry Andric#endif 14300b57cec5SDimitry Andric}; 14310b57cec5SDimitry Andric 14320b57cec5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 14330b57cec5SDimitry Andricvoid __throw_bad_function_call() 14340b57cec5SDimitry Andric{ 14350b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 14360b57cec5SDimitry Andric throw bad_function_call(); 14370b57cec5SDimitry Andric#else 14380b57cec5SDimitry Andric _VSTD::abort(); 14390b57cec5SDimitry Andric#endif 14400b57cec5SDimitry Andric} 14410b57cec5SDimitry Andric 14425ffd83dbSDimitry Andric#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated) 14435ffd83dbSDimitry Andric# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \ 14445ffd83dbSDimitry Andric __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type"))) 14455ffd83dbSDimitry Andric#else 14465ffd83dbSDimitry Andric# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */ 14475ffd83dbSDimitry Andric#endif 14485ffd83dbSDimitry Andric 14495ffd83dbSDimitry Andrictemplate<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined 14500b57cec5SDimitry Andric 14510b57cec5SDimitry Andricnamespace __function 14520b57cec5SDimitry Andric{ 14530b57cec5SDimitry Andric 14540b57cec5SDimitry Andrictemplate<class _Rp> 14550b57cec5SDimitry Andricstruct __maybe_derive_from_unary_function 14560b57cec5SDimitry Andric{ 14570b57cec5SDimitry Andric}; 14580b57cec5SDimitry Andric 14590b57cec5SDimitry Andrictemplate<class _Rp, class _A1> 14600b57cec5SDimitry Andricstruct __maybe_derive_from_unary_function<_Rp(_A1)> 14610b57cec5SDimitry Andric : public unary_function<_A1, _Rp> 14620b57cec5SDimitry Andric{ 14630b57cec5SDimitry Andric}; 14640b57cec5SDimitry Andric 14650b57cec5SDimitry Andrictemplate<class _Rp> 14660b57cec5SDimitry Andricstruct __maybe_derive_from_binary_function 14670b57cec5SDimitry Andric{ 14680b57cec5SDimitry Andric}; 14690b57cec5SDimitry Andric 14700b57cec5SDimitry Andrictemplate<class _Rp, class _A1, class _A2> 14710b57cec5SDimitry Andricstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> 14720b57cec5SDimitry Andric : public binary_function<_A1, _A2, _Rp> 14730b57cec5SDimitry Andric{ 14740b57cec5SDimitry Andric}; 14750b57cec5SDimitry Andric 14760b57cec5SDimitry Andrictemplate <class _Fp> 14770b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 14780b57cec5SDimitry Andricbool __not_null(_Fp const&) { return true; } 14790b57cec5SDimitry Andric 14800b57cec5SDimitry Andrictemplate <class _Fp> 14810b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 14820b57cec5SDimitry Andricbool __not_null(_Fp* __ptr) { return __ptr; } 14830b57cec5SDimitry Andric 14840b57cec5SDimitry Andrictemplate <class _Ret, class _Class> 14850b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 14860b57cec5SDimitry Andricbool __not_null(_Ret _Class::*__ptr) { return __ptr; } 14870b57cec5SDimitry Andric 14880b57cec5SDimitry Andrictemplate <class _Fp> 14890b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 14900b57cec5SDimitry Andricbool __not_null(function<_Fp> const& __f) { return !!__f; } 14910b57cec5SDimitry Andric 14925ffd83dbSDimitry Andric#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS 14935ffd83dbSDimitry Andrictemplate <class _Rp, class ..._Args> 14945ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY 14955ffd83dbSDimitry Andricbool __not_null(_Rp (^__p)(_Args...)) { return __p; } 14965ffd83dbSDimitry Andric#endif 14975ffd83dbSDimitry Andric 14980b57cec5SDimitry Andric} // namespace __function 14990b57cec5SDimitry Andric 15000b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 15010b57cec5SDimitry Andric 15020b57cec5SDimitry Andricnamespace __function { 15030b57cec5SDimitry Andric 15040b57cec5SDimitry Andric// __alloc_func holds a functor and an allocator. 15050b57cec5SDimitry Andric 15060b57cec5SDimitry Andrictemplate <class _Fp, class _Ap, class _FB> class __alloc_func; 15070b57cec5SDimitry Andrictemplate <class _Fp, class _FB> 15080b57cec5SDimitry Andricclass __default_alloc_func; 15090b57cec5SDimitry Andric 15100b57cec5SDimitry Andrictemplate <class _Fp, class _Ap, class _Rp, class... _ArgTypes> 15110b57cec5SDimitry Andricclass __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> 15120b57cec5SDimitry Andric{ 15130b57cec5SDimitry Andric __compressed_pair<_Fp, _Ap> __f_; 15140b57cec5SDimitry Andric 15150b57cec5SDimitry Andric public: 15160b57cec5SDimitry Andric typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; 15170b57cec5SDimitry Andric typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc; 15180b57cec5SDimitry Andric 15190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15200b57cec5SDimitry Andric const _Target& __target() const { return __f_.first(); } 15210b57cec5SDimitry Andric 15220b57cec5SDimitry Andric // WIN32 APIs may define __allocator, so use __get_allocator instead. 15230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15240b57cec5SDimitry Andric const _Alloc& __get_allocator() const { return __f_.second(); } 15250b57cec5SDimitry Andric 15260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15270b57cec5SDimitry Andric explicit __alloc_func(_Target&& __f) 15280b57cec5SDimitry Andric : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 15290b57cec5SDimitry Andric _VSTD::forward_as_tuple()) 15300b57cec5SDimitry Andric { 15310b57cec5SDimitry Andric } 15320b57cec5SDimitry Andric 15330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15340b57cec5SDimitry Andric explicit __alloc_func(const _Target& __f, const _Alloc& __a) 15350b57cec5SDimitry Andric : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 15360b57cec5SDimitry Andric _VSTD::forward_as_tuple(__a)) 15370b57cec5SDimitry Andric { 15380b57cec5SDimitry Andric } 15390b57cec5SDimitry Andric 15400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15410b57cec5SDimitry Andric explicit __alloc_func(const _Target& __f, _Alloc&& __a) 15420b57cec5SDimitry Andric : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 15430b57cec5SDimitry Andric _VSTD::forward_as_tuple(_VSTD::move(__a))) 15440b57cec5SDimitry Andric { 15450b57cec5SDimitry Andric } 15460b57cec5SDimitry Andric 15470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15480b57cec5SDimitry Andric explicit __alloc_func(_Target&& __f, _Alloc&& __a) 15490b57cec5SDimitry Andric : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 15500b57cec5SDimitry Andric _VSTD::forward_as_tuple(_VSTD::move(__a))) 15510b57cec5SDimitry Andric { 15520b57cec5SDimitry Andric } 15530b57cec5SDimitry Andric 15540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15550b57cec5SDimitry Andric _Rp operator()(_ArgTypes&&... __arg) 15560b57cec5SDimitry Andric { 15570b57cec5SDimitry Andric typedef __invoke_void_return_wrapper<_Rp> _Invoker; 15580b57cec5SDimitry Andric return _Invoker::__call(__f_.first(), 15590b57cec5SDimitry Andric _VSTD::forward<_ArgTypes>(__arg)...); 15600b57cec5SDimitry Andric } 15610b57cec5SDimitry Andric 15620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15630b57cec5SDimitry Andric __alloc_func* __clone() const 15640b57cec5SDimitry Andric { 15650b57cec5SDimitry Andric typedef allocator_traits<_Alloc> __alloc_traits; 15660b57cec5SDimitry Andric typedef 15670b57cec5SDimitry Andric typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type 15680b57cec5SDimitry Andric _AA; 15690b57cec5SDimitry Andric _AA __a(__f_.second()); 15700b57cec5SDimitry Andric typedef __allocator_destructor<_AA> _Dp; 15710b57cec5SDimitry Andric unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 15720b57cec5SDimitry Andric ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); 15730b57cec5SDimitry Andric return __hold.release(); 15740b57cec5SDimitry Andric } 15750b57cec5SDimitry Andric 15760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15770b57cec5SDimitry Andric void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } 15780b57cec5SDimitry Andric 15790b57cec5SDimitry Andric static void __destroy_and_delete(__alloc_func* __f) { 15800b57cec5SDimitry Andric typedef allocator_traits<_Alloc> __alloc_traits; 15810b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type 15820b57cec5SDimitry Andric _FunAlloc; 15830b57cec5SDimitry Andric _FunAlloc __a(__f->__get_allocator()); 15840b57cec5SDimitry Andric __f->destroy(); 15850b57cec5SDimitry Andric __a.deallocate(__f, 1); 15860b57cec5SDimitry Andric } 15870b57cec5SDimitry Andric}; 15880b57cec5SDimitry Andric 15890b57cec5SDimitry Andrictemplate <class _Fp, class _Rp, class... _ArgTypes> 15900b57cec5SDimitry Andricclass __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { 15910b57cec5SDimitry Andric _Fp __f_; 15920b57cec5SDimitry Andric 15930b57cec5SDimitry Andricpublic: 15940b57cec5SDimitry Andric typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; 15950b57cec5SDimitry Andric 15960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15970b57cec5SDimitry Andric const _Target& __target() const { return __f_; } 15980b57cec5SDimitry Andric 15990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1600*e8d8bef9SDimitry Andric explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {} 16010b57cec5SDimitry Andric 16020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16030b57cec5SDimitry Andric explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} 16040b57cec5SDimitry Andric 16050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16060b57cec5SDimitry Andric _Rp operator()(_ArgTypes&&... __arg) { 16070b57cec5SDimitry Andric typedef __invoke_void_return_wrapper<_Rp> _Invoker; 16080b57cec5SDimitry Andric return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...); 16090b57cec5SDimitry Andric } 16100b57cec5SDimitry Andric 16110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16120b57cec5SDimitry Andric __default_alloc_func* __clone() const { 16130b57cec5SDimitry Andric __builtin_new_allocator::__holder_t __hold = 16140b57cec5SDimitry Andric __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); 16150b57cec5SDimitry Andric __default_alloc_func* __res = 1616*e8d8bef9SDimitry Andric ::new ((void*)__hold.get()) __default_alloc_func(__f_); 16170b57cec5SDimitry Andric (void)__hold.release(); 16180b57cec5SDimitry Andric return __res; 16190b57cec5SDimitry Andric } 16200b57cec5SDimitry Andric 16210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16220b57cec5SDimitry Andric void destroy() _NOEXCEPT { __f_.~_Target(); } 16230b57cec5SDimitry Andric 16240b57cec5SDimitry Andric static void __destroy_and_delete(__default_alloc_func* __f) { 16250b57cec5SDimitry Andric __f->destroy(); 16260b57cec5SDimitry Andric __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); 16270b57cec5SDimitry Andric } 16280b57cec5SDimitry Andric}; 16290b57cec5SDimitry Andric 16300b57cec5SDimitry Andric// __base provides an abstract interface for copyable functors. 16310b57cec5SDimitry Andric 16325ffd83dbSDimitry Andrictemplate<class _Fp> class _LIBCPP_TEMPLATE_VIS __base; 16330b57cec5SDimitry Andric 16340b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 16350b57cec5SDimitry Andricclass __base<_Rp(_ArgTypes...)> 16360b57cec5SDimitry Andric{ 16370b57cec5SDimitry Andric __base(const __base&); 16380b57cec5SDimitry Andric __base& operator=(const __base&); 16390b57cec5SDimitry Andricpublic: 16400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __base() {} 16410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} 16420b57cec5SDimitry Andric virtual __base* __clone() const = 0; 16430b57cec5SDimitry Andric virtual void __clone(__base*) const = 0; 16440b57cec5SDimitry Andric virtual void destroy() _NOEXCEPT = 0; 16450b57cec5SDimitry Andric virtual void destroy_deallocate() _NOEXCEPT = 0; 16460b57cec5SDimitry Andric virtual _Rp operator()(_ArgTypes&& ...) = 0; 16470b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 16480b57cec5SDimitry Andric virtual const void* target(const type_info&) const _NOEXCEPT = 0; 16490b57cec5SDimitry Andric virtual const std::type_info& target_type() const _NOEXCEPT = 0; 16500b57cec5SDimitry Andric#endif // _LIBCPP_NO_RTTI 16510b57cec5SDimitry Andric}; 16520b57cec5SDimitry Andric 16530b57cec5SDimitry Andric// __func implements __base for a given functor type. 16540b57cec5SDimitry Andric 16550b57cec5SDimitry Andrictemplate<class _FD, class _Alloc, class _FB> class __func; 16560b57cec5SDimitry Andric 16570b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 16580b57cec5SDimitry Andricclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)> 16590b57cec5SDimitry Andric : public __base<_Rp(_ArgTypes...)> 16600b57cec5SDimitry Andric{ 16610b57cec5SDimitry Andric __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; 16620b57cec5SDimitry Andricpublic: 16630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16640b57cec5SDimitry Andric explicit __func(_Fp&& __f) 16650b57cec5SDimitry Andric : __f_(_VSTD::move(__f)) {} 16660b57cec5SDimitry Andric 16670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16680b57cec5SDimitry Andric explicit __func(const _Fp& __f, const _Alloc& __a) 16690b57cec5SDimitry Andric : __f_(__f, __a) {} 16700b57cec5SDimitry Andric 16710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16720b57cec5SDimitry Andric explicit __func(const _Fp& __f, _Alloc&& __a) 16730b57cec5SDimitry Andric : __f_(__f, _VSTD::move(__a)) {} 16740b57cec5SDimitry Andric 16750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 16760b57cec5SDimitry Andric explicit __func(_Fp&& __f, _Alloc&& __a) 16770b57cec5SDimitry Andric : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 16780b57cec5SDimitry Andric 16790b57cec5SDimitry Andric virtual __base<_Rp(_ArgTypes...)>* __clone() const; 16800b57cec5SDimitry Andric virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; 16810b57cec5SDimitry Andric virtual void destroy() _NOEXCEPT; 16820b57cec5SDimitry Andric virtual void destroy_deallocate() _NOEXCEPT; 16830b57cec5SDimitry Andric virtual _Rp operator()(_ArgTypes&&... __arg); 16840b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 16850b57cec5SDimitry Andric virtual const void* target(const type_info&) const _NOEXCEPT; 16860b57cec5SDimitry Andric virtual const std::type_info& target_type() const _NOEXCEPT; 16870b57cec5SDimitry Andric#endif // _LIBCPP_NO_RTTI 16880b57cec5SDimitry Andric}; 16890b57cec5SDimitry Andric 16900b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 16910b57cec5SDimitry Andric__base<_Rp(_ArgTypes...)>* 16920b57cec5SDimitry Andric__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const 16930b57cec5SDimitry Andric{ 16940b57cec5SDimitry Andric typedef allocator_traits<_Alloc> __alloc_traits; 16950b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 16960b57cec5SDimitry Andric _Ap __a(__f_.__get_allocator()); 16970b57cec5SDimitry Andric typedef __allocator_destructor<_Ap> _Dp; 16980b57cec5SDimitry Andric unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 16990b57cec5SDimitry Andric ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); 17000b57cec5SDimitry Andric return __hold.release(); 17010b57cec5SDimitry Andric} 17020b57cec5SDimitry Andric 17030b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 17040b57cec5SDimitry Andricvoid 17050b57cec5SDimitry Andric__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const 17060b57cec5SDimitry Andric{ 1707*e8d8bef9SDimitry Andric ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator()); 17080b57cec5SDimitry Andric} 17090b57cec5SDimitry Andric 17100b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 17110b57cec5SDimitry Andricvoid 17120b57cec5SDimitry Andric__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT 17130b57cec5SDimitry Andric{ 17140b57cec5SDimitry Andric __f_.destroy(); 17150b57cec5SDimitry Andric} 17160b57cec5SDimitry Andric 17170b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 17180b57cec5SDimitry Andricvoid 17190b57cec5SDimitry Andric__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT 17200b57cec5SDimitry Andric{ 17210b57cec5SDimitry Andric typedef allocator_traits<_Alloc> __alloc_traits; 17220b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 17230b57cec5SDimitry Andric _Ap __a(__f_.__get_allocator()); 17240b57cec5SDimitry Andric __f_.destroy(); 17250b57cec5SDimitry Andric __a.deallocate(this, 1); 17260b57cec5SDimitry Andric} 17270b57cec5SDimitry Andric 17280b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 17290b57cec5SDimitry Andric_Rp 17300b57cec5SDimitry Andric__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 17310b57cec5SDimitry Andric{ 17320b57cec5SDimitry Andric return __f_(_VSTD::forward<_ArgTypes>(__arg)...); 17330b57cec5SDimitry Andric} 17340b57cec5SDimitry Andric 17350b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 17360b57cec5SDimitry Andric 17370b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 17380b57cec5SDimitry Andricconst void* 17390b57cec5SDimitry Andric__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT 17400b57cec5SDimitry Andric{ 17410b57cec5SDimitry Andric if (__ti == typeid(_Fp)) 17420b57cec5SDimitry Andric return &__f_.__target(); 1743*e8d8bef9SDimitry Andric return nullptr; 17440b57cec5SDimitry Andric} 17450b57cec5SDimitry Andric 17460b57cec5SDimitry Andrictemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 17470b57cec5SDimitry Andricconst std::type_info& 17480b57cec5SDimitry Andric__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 17490b57cec5SDimitry Andric{ 17500b57cec5SDimitry Andric return typeid(_Fp); 17510b57cec5SDimitry Andric} 17520b57cec5SDimitry Andric 17530b57cec5SDimitry Andric#endif // _LIBCPP_NO_RTTI 17540b57cec5SDimitry Andric 17550b57cec5SDimitry Andric// __value_func creates a value-type from a __func. 17560b57cec5SDimitry Andric 17570b57cec5SDimitry Andrictemplate <class _Fp> class __value_func; 17580b57cec5SDimitry Andric 17590b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)> 17600b57cec5SDimitry Andric{ 17610b57cec5SDimitry Andric typename aligned_storage<3 * sizeof(void*)>::type __buf_; 17620b57cec5SDimitry Andric 17630b57cec5SDimitry Andric typedef __base<_Rp(_ArgTypes...)> __func; 17640b57cec5SDimitry Andric __func* __f_; 17650b57cec5SDimitry Andric 17660b57cec5SDimitry Andric _LIBCPP_NO_CFI static __func* __as_base(void* p) 17670b57cec5SDimitry Andric { 17680b57cec5SDimitry Andric return reinterpret_cast<__func*>(p); 17690b57cec5SDimitry Andric } 17700b57cec5SDimitry Andric 17710b57cec5SDimitry Andric public: 17720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1773*e8d8bef9SDimitry Andric __value_func() _NOEXCEPT : __f_(nullptr) {} 17740b57cec5SDimitry Andric 17750b57cec5SDimitry Andric template <class _Fp, class _Alloc> 17760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a) 1777*e8d8bef9SDimitry Andric : __f_(nullptr) 17780b57cec5SDimitry Andric { 17790b57cec5SDimitry Andric typedef allocator_traits<_Alloc> __alloc_traits; 17800b57cec5SDimitry Andric typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; 17810b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type 17820b57cec5SDimitry Andric _FunAlloc; 17830b57cec5SDimitry Andric 17840b57cec5SDimitry Andric if (__function::__not_null(__f)) 17850b57cec5SDimitry Andric { 17860b57cec5SDimitry Andric _FunAlloc __af(__a); 17870b57cec5SDimitry Andric if (sizeof(_Fun) <= sizeof(__buf_) && 17880b57cec5SDimitry Andric is_nothrow_copy_constructible<_Fp>::value && 17890b57cec5SDimitry Andric is_nothrow_copy_constructible<_FunAlloc>::value) 17900b57cec5SDimitry Andric { 17910b57cec5SDimitry Andric __f_ = 17920b57cec5SDimitry Andric ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af)); 17930b57cec5SDimitry Andric } 17940b57cec5SDimitry Andric else 17950b57cec5SDimitry Andric { 17960b57cec5SDimitry Andric typedef __allocator_destructor<_FunAlloc> _Dp; 17970b57cec5SDimitry Andric unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); 17980b57cec5SDimitry Andric ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a)); 17990b57cec5SDimitry Andric __f_ = __hold.release(); 18000b57cec5SDimitry Andric } 18010b57cec5SDimitry Andric } 18020b57cec5SDimitry Andric } 18030b57cec5SDimitry Andric 18040b57cec5SDimitry Andric template <class _Fp, 18050b57cec5SDimitry Andric class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type> 18060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f) 1807*e8d8bef9SDimitry Andric : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {} 18080b57cec5SDimitry Andric 18090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18100b57cec5SDimitry Andric __value_func(const __value_func& __f) 18110b57cec5SDimitry Andric { 1812*e8d8bef9SDimitry Andric if (__f.__f_ == nullptr) 1813*e8d8bef9SDimitry Andric __f_ = nullptr; 18140b57cec5SDimitry Andric else if ((void*)__f.__f_ == &__f.__buf_) 18150b57cec5SDimitry Andric { 18160b57cec5SDimitry Andric __f_ = __as_base(&__buf_); 18170b57cec5SDimitry Andric __f.__f_->__clone(__f_); 18180b57cec5SDimitry Andric } 18190b57cec5SDimitry Andric else 18200b57cec5SDimitry Andric __f_ = __f.__f_->__clone(); 18210b57cec5SDimitry Andric } 18220b57cec5SDimitry Andric 18230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18240b57cec5SDimitry Andric __value_func(__value_func&& __f) _NOEXCEPT 18250b57cec5SDimitry Andric { 1826*e8d8bef9SDimitry Andric if (__f.__f_ == nullptr) 1827*e8d8bef9SDimitry Andric __f_ = nullptr; 18280b57cec5SDimitry Andric else if ((void*)__f.__f_ == &__f.__buf_) 18290b57cec5SDimitry Andric { 18300b57cec5SDimitry Andric __f_ = __as_base(&__buf_); 18310b57cec5SDimitry Andric __f.__f_->__clone(__f_); 18320b57cec5SDimitry Andric } 18330b57cec5SDimitry Andric else 18340b57cec5SDimitry Andric { 18350b57cec5SDimitry Andric __f_ = __f.__f_; 1836*e8d8bef9SDimitry Andric __f.__f_ = nullptr; 18370b57cec5SDimitry Andric } 18380b57cec5SDimitry Andric } 18390b57cec5SDimitry Andric 18400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18410b57cec5SDimitry Andric ~__value_func() 18420b57cec5SDimitry Andric { 18430b57cec5SDimitry Andric if ((void*)__f_ == &__buf_) 18440b57cec5SDimitry Andric __f_->destroy(); 18450b57cec5SDimitry Andric else if (__f_) 18460b57cec5SDimitry Andric __f_->destroy_deallocate(); 18470b57cec5SDimitry Andric } 18480b57cec5SDimitry Andric 18490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18500b57cec5SDimitry Andric __value_func& operator=(__value_func&& __f) 18510b57cec5SDimitry Andric { 18520b57cec5SDimitry Andric *this = nullptr; 1853*e8d8bef9SDimitry Andric if (__f.__f_ == nullptr) 1854*e8d8bef9SDimitry Andric __f_ = nullptr; 18550b57cec5SDimitry Andric else if ((void*)__f.__f_ == &__f.__buf_) 18560b57cec5SDimitry Andric { 18570b57cec5SDimitry Andric __f_ = __as_base(&__buf_); 18580b57cec5SDimitry Andric __f.__f_->__clone(__f_); 18590b57cec5SDimitry Andric } 18600b57cec5SDimitry Andric else 18610b57cec5SDimitry Andric { 18620b57cec5SDimitry Andric __f_ = __f.__f_; 1863*e8d8bef9SDimitry Andric __f.__f_ = nullptr; 18640b57cec5SDimitry Andric } 18650b57cec5SDimitry Andric return *this; 18660b57cec5SDimitry Andric } 18670b57cec5SDimitry Andric 18680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18690b57cec5SDimitry Andric __value_func& operator=(nullptr_t) 18700b57cec5SDimitry Andric { 18710b57cec5SDimitry Andric __func* __f = __f_; 1872*e8d8bef9SDimitry Andric __f_ = nullptr; 18730b57cec5SDimitry Andric if ((void*)__f == &__buf_) 18740b57cec5SDimitry Andric __f->destroy(); 18750b57cec5SDimitry Andric else if (__f) 18760b57cec5SDimitry Andric __f->destroy_deallocate(); 18770b57cec5SDimitry Andric return *this; 18780b57cec5SDimitry Andric } 18790b57cec5SDimitry Andric 18800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18810b57cec5SDimitry Andric _Rp operator()(_ArgTypes&&... __args) const 18820b57cec5SDimitry Andric { 1883*e8d8bef9SDimitry Andric if (__f_ == nullptr) 18840b57cec5SDimitry Andric __throw_bad_function_call(); 18850b57cec5SDimitry Andric return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...); 18860b57cec5SDimitry Andric } 18870b57cec5SDimitry Andric 18880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 18890b57cec5SDimitry Andric void swap(__value_func& __f) _NOEXCEPT 18900b57cec5SDimitry Andric { 18910b57cec5SDimitry Andric if (&__f == this) 18920b57cec5SDimitry Andric return; 18930b57cec5SDimitry Andric if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) 18940b57cec5SDimitry Andric { 18950b57cec5SDimitry Andric typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 18960b57cec5SDimitry Andric __func* __t = __as_base(&__tempbuf); 18970b57cec5SDimitry Andric __f_->__clone(__t); 18980b57cec5SDimitry Andric __f_->destroy(); 1899*e8d8bef9SDimitry Andric __f_ = nullptr; 19000b57cec5SDimitry Andric __f.__f_->__clone(__as_base(&__buf_)); 19010b57cec5SDimitry Andric __f.__f_->destroy(); 1902*e8d8bef9SDimitry Andric __f.__f_ = nullptr; 19030b57cec5SDimitry Andric __f_ = __as_base(&__buf_); 19040b57cec5SDimitry Andric __t->__clone(__as_base(&__f.__buf_)); 19050b57cec5SDimitry Andric __t->destroy(); 19060b57cec5SDimitry Andric __f.__f_ = __as_base(&__f.__buf_); 19070b57cec5SDimitry Andric } 19080b57cec5SDimitry Andric else if ((void*)__f_ == &__buf_) 19090b57cec5SDimitry Andric { 19100b57cec5SDimitry Andric __f_->__clone(__as_base(&__f.__buf_)); 19110b57cec5SDimitry Andric __f_->destroy(); 19120b57cec5SDimitry Andric __f_ = __f.__f_; 19130b57cec5SDimitry Andric __f.__f_ = __as_base(&__f.__buf_); 19140b57cec5SDimitry Andric } 19150b57cec5SDimitry Andric else if ((void*)__f.__f_ == &__f.__buf_) 19160b57cec5SDimitry Andric { 19170b57cec5SDimitry Andric __f.__f_->__clone(__as_base(&__buf_)); 19180b57cec5SDimitry Andric __f.__f_->destroy(); 19190b57cec5SDimitry Andric __f.__f_ = __f_; 19200b57cec5SDimitry Andric __f_ = __as_base(&__buf_); 19210b57cec5SDimitry Andric } 19220b57cec5SDimitry Andric else 19230b57cec5SDimitry Andric _VSTD::swap(__f_, __f.__f_); 19240b57cec5SDimitry Andric } 19250b57cec5SDimitry Andric 19260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1927*e8d8bef9SDimitry Andric _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; } 19280b57cec5SDimitry Andric 19290b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 19300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19310b57cec5SDimitry Andric const std::type_info& target_type() const _NOEXCEPT 19320b57cec5SDimitry Andric { 1933*e8d8bef9SDimitry Andric if (__f_ == nullptr) 19340b57cec5SDimitry Andric return typeid(void); 19350b57cec5SDimitry Andric return __f_->target_type(); 19360b57cec5SDimitry Andric } 19370b57cec5SDimitry Andric 19380b57cec5SDimitry Andric template <typename _Tp> 19390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT 19400b57cec5SDimitry Andric { 1941*e8d8bef9SDimitry Andric if (__f_ == nullptr) 1942*e8d8bef9SDimitry Andric return nullptr; 19430b57cec5SDimitry Andric return (const _Tp*)__f_->target(typeid(_Tp)); 19440b57cec5SDimitry Andric } 19450b57cec5SDimitry Andric#endif // _LIBCPP_NO_RTTI 19460b57cec5SDimitry Andric}; 19470b57cec5SDimitry Andric 19480b57cec5SDimitry Andric// Storage for a functor object, to be used with __policy to manage copy and 19490b57cec5SDimitry Andric// destruction. 19500b57cec5SDimitry Andricunion __policy_storage 19510b57cec5SDimitry Andric{ 19520b57cec5SDimitry Andric mutable char __small[sizeof(void*) * 2]; 19530b57cec5SDimitry Andric void* __large; 19540b57cec5SDimitry Andric}; 19550b57cec5SDimitry Andric 19560b57cec5SDimitry Andric// True if _Fun can safely be held in __policy_storage.__small. 19570b57cec5SDimitry Andrictemplate <typename _Fun> 19580b57cec5SDimitry Andricstruct __use_small_storage 19590b57cec5SDimitry Andric : public _VSTD::integral_constant< 19600b57cec5SDimitry Andric bool, sizeof(_Fun) <= sizeof(__policy_storage) && 19610b57cec5SDimitry Andric _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) && 19620b57cec5SDimitry Andric _VSTD::is_trivially_copy_constructible<_Fun>::value && 19630b57cec5SDimitry Andric _VSTD::is_trivially_destructible<_Fun>::value> {}; 19640b57cec5SDimitry Andric 19650b57cec5SDimitry Andric// Policy contains information about how to copy, destroy, and move the 19660b57cec5SDimitry Andric// underlying functor. You can think of it as a vtable of sorts. 19670b57cec5SDimitry Andricstruct __policy 19680b57cec5SDimitry Andric{ 19690b57cec5SDimitry Andric // Used to copy or destroy __large values. null for trivial objects. 19700b57cec5SDimitry Andric void* (*const __clone)(const void*); 19710b57cec5SDimitry Andric void (*const __destroy)(void*); 19720b57cec5SDimitry Andric 19730b57cec5SDimitry Andric // True if this is the null policy (no value). 19740b57cec5SDimitry Andric const bool __is_null; 19750b57cec5SDimitry Andric 19760b57cec5SDimitry Andric // The target type. May be null if RTTI is disabled. 19770b57cec5SDimitry Andric const std::type_info* const __type_info; 19780b57cec5SDimitry Andric 19790b57cec5SDimitry Andric // Returns a pointer to a static policy object suitable for the functor 19800b57cec5SDimitry Andric // type. 19810b57cec5SDimitry Andric template <typename _Fun> 19820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static const __policy* __create() 19830b57cec5SDimitry Andric { 19840b57cec5SDimitry Andric return __choose_policy<_Fun>(__use_small_storage<_Fun>()); 19850b57cec5SDimitry Andric } 19860b57cec5SDimitry Andric 19870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 19880b57cec5SDimitry Andric static const __policy* __create_empty() 19890b57cec5SDimitry Andric { 19900b57cec5SDimitry Andric static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr, 19910b57cec5SDimitry Andric true, 19920b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 19930b57cec5SDimitry Andric &typeid(void) 19940b57cec5SDimitry Andric#else 19950b57cec5SDimitry Andric nullptr 19960b57cec5SDimitry Andric#endif 19970b57cec5SDimitry Andric }; 19980b57cec5SDimitry Andric return &__policy_; 19990b57cec5SDimitry Andric } 20000b57cec5SDimitry Andric 20010b57cec5SDimitry Andric private: 20020b57cec5SDimitry Andric template <typename _Fun> static void* __large_clone(const void* __s) 20030b57cec5SDimitry Andric { 20040b57cec5SDimitry Andric const _Fun* __f = static_cast<const _Fun*>(__s); 20050b57cec5SDimitry Andric return __f->__clone(); 20060b57cec5SDimitry Andric } 20070b57cec5SDimitry Andric 20080b57cec5SDimitry Andric template <typename _Fun> 20090b57cec5SDimitry Andric static void __large_destroy(void* __s) { 20100b57cec5SDimitry Andric _Fun::__destroy_and_delete(static_cast<_Fun*>(__s)); 20110b57cec5SDimitry Andric } 20120b57cec5SDimitry Andric 20130b57cec5SDimitry Andric template <typename _Fun> 20140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static const __policy* 20150b57cec5SDimitry Andric __choose_policy(/* is_small = */ false_type) { 20160b57cec5SDimitry Andric static const _LIBCPP_CONSTEXPR __policy __policy_ = { 20170b57cec5SDimitry Andric &__large_clone<_Fun>, &__large_destroy<_Fun>, false, 20180b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 20190b57cec5SDimitry Andric &typeid(typename _Fun::_Target) 20200b57cec5SDimitry Andric#else 20210b57cec5SDimitry Andric nullptr 20220b57cec5SDimitry Andric#endif 20230b57cec5SDimitry Andric }; 20240b57cec5SDimitry Andric return &__policy_; 20250b57cec5SDimitry Andric } 20260b57cec5SDimitry Andric 20270b57cec5SDimitry Andric template <typename _Fun> 20280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static const __policy* 20290b57cec5SDimitry Andric __choose_policy(/* is_small = */ true_type) 20300b57cec5SDimitry Andric { 20310b57cec5SDimitry Andric static const _LIBCPP_CONSTEXPR __policy __policy_ = { 20320b57cec5SDimitry Andric nullptr, nullptr, false, 20330b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 20340b57cec5SDimitry Andric &typeid(typename _Fun::_Target) 20350b57cec5SDimitry Andric#else 20360b57cec5SDimitry Andric nullptr 20370b57cec5SDimitry Andric#endif 20380b57cec5SDimitry Andric }; 20390b57cec5SDimitry Andric return &__policy_; 20400b57cec5SDimitry Andric } 20410b57cec5SDimitry Andric}; 20420b57cec5SDimitry Andric 20430b57cec5SDimitry Andric// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is 20440b57cec5SDimitry Andric// faster for types that can be passed in registers. 20450b57cec5SDimitry Andrictemplate <typename _Tp> 20460b57cec5SDimitry Andricusing __fast_forward = 20470b57cec5SDimitry Andric typename _VSTD::conditional<_VSTD::is_scalar<_Tp>::value, _Tp, _Tp&&>::type; 20480b57cec5SDimitry Andric 20490b57cec5SDimitry Andric// __policy_invoker calls an instance of __alloc_func held in __policy_storage. 20500b57cec5SDimitry Andric 20510b57cec5SDimitry Andrictemplate <class _Fp> struct __policy_invoker; 20520b57cec5SDimitry Andric 20530b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 20540b57cec5SDimitry Andricstruct __policy_invoker<_Rp(_ArgTypes...)> 20550b57cec5SDimitry Andric{ 20560b57cec5SDimitry Andric typedef _Rp (*__Call)(const __policy_storage*, 20570b57cec5SDimitry Andric __fast_forward<_ArgTypes>...); 20580b57cec5SDimitry Andric 20590b57cec5SDimitry Andric __Call __call_; 20600b57cec5SDimitry Andric 20610b57cec5SDimitry Andric // Creates an invoker that throws bad_function_call. 20620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20630b57cec5SDimitry Andric __policy_invoker() : __call_(&__call_empty) {} 20640b57cec5SDimitry Andric 20650b57cec5SDimitry Andric // Creates an invoker that calls the given instance of __func. 20660b57cec5SDimitry Andric template <typename _Fun> 20670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create() 20680b57cec5SDimitry Andric { 20690b57cec5SDimitry Andric return __policy_invoker(&__call_impl<_Fun>); 20700b57cec5SDimitry Andric } 20710b57cec5SDimitry Andric 20720b57cec5SDimitry Andric private: 20730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20740b57cec5SDimitry Andric explicit __policy_invoker(__Call __c) : __call_(__c) {} 20750b57cec5SDimitry Andric 20760b57cec5SDimitry Andric static _Rp __call_empty(const __policy_storage*, 20770b57cec5SDimitry Andric __fast_forward<_ArgTypes>...) 20780b57cec5SDimitry Andric { 20790b57cec5SDimitry Andric __throw_bad_function_call(); 20800b57cec5SDimitry Andric } 20810b57cec5SDimitry Andric 20820b57cec5SDimitry Andric template <typename _Fun> 20830b57cec5SDimitry Andric static _Rp __call_impl(const __policy_storage* __buf, 20840b57cec5SDimitry Andric __fast_forward<_ArgTypes>... __args) 20850b57cec5SDimitry Andric { 20860b57cec5SDimitry Andric _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value 20870b57cec5SDimitry Andric ? &__buf->__small 20880b57cec5SDimitry Andric : __buf->__large); 20890b57cec5SDimitry Andric return (*__f)(_VSTD::forward<_ArgTypes>(__args)...); 20900b57cec5SDimitry Andric } 20910b57cec5SDimitry Andric}; 20920b57cec5SDimitry Andric 20930b57cec5SDimitry Andric// __policy_func uses a __policy and __policy_invoker to create a type-erased, 20940b57cec5SDimitry Andric// copyable functor. 20950b57cec5SDimitry Andric 20960b57cec5SDimitry Andrictemplate <class _Fp> class __policy_func; 20970b57cec5SDimitry Andric 20980b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)> 20990b57cec5SDimitry Andric{ 21000b57cec5SDimitry Andric // Inline storage for small objects. 21010b57cec5SDimitry Andric __policy_storage __buf_; 21020b57cec5SDimitry Andric 21030b57cec5SDimitry Andric // Calls the value stored in __buf_. This could technically be part of 21040b57cec5SDimitry Andric // policy, but storing it here eliminates a level of indirection inside 21050b57cec5SDimitry Andric // operator(). 21060b57cec5SDimitry Andric typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker; 21070b57cec5SDimitry Andric __invoker __invoker_; 21080b57cec5SDimitry Andric 21090b57cec5SDimitry Andric // The policy that describes how to move / copy / destroy __buf_. Never 21100b57cec5SDimitry Andric // null, even if the function is empty. 21110b57cec5SDimitry Andric const __policy* __policy_; 21120b57cec5SDimitry Andric 21130b57cec5SDimitry Andric public: 21140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21150b57cec5SDimitry Andric __policy_func() : __policy_(__policy::__create_empty()) {} 21160b57cec5SDimitry Andric 21170b57cec5SDimitry Andric template <class _Fp, class _Alloc> 21180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a) 21190b57cec5SDimitry Andric : __policy_(__policy::__create_empty()) 21200b57cec5SDimitry Andric { 21210b57cec5SDimitry Andric typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; 21220b57cec5SDimitry Andric typedef allocator_traits<_Alloc> __alloc_traits; 21230b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type 21240b57cec5SDimitry Andric _FunAlloc; 21250b57cec5SDimitry Andric 21260b57cec5SDimitry Andric if (__function::__not_null(__f)) 21270b57cec5SDimitry Andric { 21280b57cec5SDimitry Andric __invoker_ = __invoker::template __create<_Fun>(); 21290b57cec5SDimitry Andric __policy_ = __policy::__create<_Fun>(); 21300b57cec5SDimitry Andric 21310b57cec5SDimitry Andric _FunAlloc __af(__a); 21320b57cec5SDimitry Andric if (__use_small_storage<_Fun>()) 21330b57cec5SDimitry Andric { 21340b57cec5SDimitry Andric ::new ((void*)&__buf_.__small) 21350b57cec5SDimitry Andric _Fun(_VSTD::move(__f), _Alloc(__af)); 21360b57cec5SDimitry Andric } 21370b57cec5SDimitry Andric else 21380b57cec5SDimitry Andric { 21390b57cec5SDimitry Andric typedef __allocator_destructor<_FunAlloc> _Dp; 21400b57cec5SDimitry Andric unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); 21410b57cec5SDimitry Andric ::new ((void*)__hold.get()) 21420b57cec5SDimitry Andric _Fun(_VSTD::move(__f), _Alloc(__af)); 21430b57cec5SDimitry Andric __buf_.__large = __hold.release(); 21440b57cec5SDimitry Andric } 21450b57cec5SDimitry Andric } 21460b57cec5SDimitry Andric } 21470b57cec5SDimitry Andric 21480b57cec5SDimitry Andric template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type> 21490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f) 21500b57cec5SDimitry Andric : __policy_(__policy::__create_empty()) { 21510b57cec5SDimitry Andric typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun; 21520b57cec5SDimitry Andric 21530b57cec5SDimitry Andric if (__function::__not_null(__f)) { 21540b57cec5SDimitry Andric __invoker_ = __invoker::template __create<_Fun>(); 21550b57cec5SDimitry Andric __policy_ = __policy::__create<_Fun>(); 21560b57cec5SDimitry Andric if (__use_small_storage<_Fun>()) { 21570b57cec5SDimitry Andric ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f)); 21580b57cec5SDimitry Andric } else { 21590b57cec5SDimitry Andric __builtin_new_allocator::__holder_t __hold = 21600b57cec5SDimitry Andric __builtin_new_allocator::__allocate_type<_Fun>(1); 2161*e8d8bef9SDimitry Andric __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f)); 21620b57cec5SDimitry Andric (void)__hold.release(); 21630b57cec5SDimitry Andric } 21640b57cec5SDimitry Andric } 21650b57cec5SDimitry Andric } 21660b57cec5SDimitry Andric 21670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21680b57cec5SDimitry Andric __policy_func(const __policy_func& __f) 21690b57cec5SDimitry Andric : __buf_(__f.__buf_), __invoker_(__f.__invoker_), 21700b57cec5SDimitry Andric __policy_(__f.__policy_) 21710b57cec5SDimitry Andric { 21720b57cec5SDimitry Andric if (__policy_->__clone) 21730b57cec5SDimitry Andric __buf_.__large = __policy_->__clone(__f.__buf_.__large); 21740b57cec5SDimitry Andric } 21750b57cec5SDimitry Andric 21760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21770b57cec5SDimitry Andric __policy_func(__policy_func&& __f) 21780b57cec5SDimitry Andric : __buf_(__f.__buf_), __invoker_(__f.__invoker_), 21790b57cec5SDimitry Andric __policy_(__f.__policy_) 21800b57cec5SDimitry Andric { 21810b57cec5SDimitry Andric if (__policy_->__destroy) 21820b57cec5SDimitry Andric { 21830b57cec5SDimitry Andric __f.__policy_ = __policy::__create_empty(); 21840b57cec5SDimitry Andric __f.__invoker_ = __invoker(); 21850b57cec5SDimitry Andric } 21860b57cec5SDimitry Andric } 21870b57cec5SDimitry Andric 21880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21890b57cec5SDimitry Andric ~__policy_func() 21900b57cec5SDimitry Andric { 21910b57cec5SDimitry Andric if (__policy_->__destroy) 21920b57cec5SDimitry Andric __policy_->__destroy(__buf_.__large); 21930b57cec5SDimitry Andric } 21940b57cec5SDimitry Andric 21950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21960b57cec5SDimitry Andric __policy_func& operator=(__policy_func&& __f) 21970b57cec5SDimitry Andric { 21980b57cec5SDimitry Andric *this = nullptr; 21990b57cec5SDimitry Andric __buf_ = __f.__buf_; 22000b57cec5SDimitry Andric __invoker_ = __f.__invoker_; 22010b57cec5SDimitry Andric __policy_ = __f.__policy_; 22020b57cec5SDimitry Andric __f.__policy_ = __policy::__create_empty(); 22030b57cec5SDimitry Andric __f.__invoker_ = __invoker(); 22040b57cec5SDimitry Andric return *this; 22050b57cec5SDimitry Andric } 22060b57cec5SDimitry Andric 22070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22080b57cec5SDimitry Andric __policy_func& operator=(nullptr_t) 22090b57cec5SDimitry Andric { 22100b57cec5SDimitry Andric const __policy* __p = __policy_; 22110b57cec5SDimitry Andric __policy_ = __policy::__create_empty(); 22120b57cec5SDimitry Andric __invoker_ = __invoker(); 22130b57cec5SDimitry Andric if (__p->__destroy) 22140b57cec5SDimitry Andric __p->__destroy(__buf_.__large); 22150b57cec5SDimitry Andric return *this; 22160b57cec5SDimitry Andric } 22170b57cec5SDimitry Andric 22180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22190b57cec5SDimitry Andric _Rp operator()(_ArgTypes&&... __args) const 22200b57cec5SDimitry Andric { 22210b57cec5SDimitry Andric return __invoker_.__call_(_VSTD::addressof(__buf_), 22220b57cec5SDimitry Andric _VSTD::forward<_ArgTypes>(__args)...); 22230b57cec5SDimitry Andric } 22240b57cec5SDimitry Andric 22250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22260b57cec5SDimitry Andric void swap(__policy_func& __f) 22270b57cec5SDimitry Andric { 22280b57cec5SDimitry Andric _VSTD::swap(__invoker_, __f.__invoker_); 22290b57cec5SDimitry Andric _VSTD::swap(__policy_, __f.__policy_); 22300b57cec5SDimitry Andric _VSTD::swap(__buf_, __f.__buf_); 22310b57cec5SDimitry Andric } 22320b57cec5SDimitry Andric 22330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22340b57cec5SDimitry Andric explicit operator bool() const _NOEXCEPT 22350b57cec5SDimitry Andric { 22360b57cec5SDimitry Andric return !__policy_->__is_null; 22370b57cec5SDimitry Andric } 22380b57cec5SDimitry Andric 22390b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 22400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22410b57cec5SDimitry Andric const std::type_info& target_type() const _NOEXCEPT 22420b57cec5SDimitry Andric { 22430b57cec5SDimitry Andric return *__policy_->__type_info; 22440b57cec5SDimitry Andric } 22450b57cec5SDimitry Andric 22460b57cec5SDimitry Andric template <typename _Tp> 22470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT 22480b57cec5SDimitry Andric { 22490b57cec5SDimitry Andric if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info) 22500b57cec5SDimitry Andric return nullptr; 22510b57cec5SDimitry Andric if (__policy_->__clone) // Out of line storage. 22520b57cec5SDimitry Andric return reinterpret_cast<const _Tp*>(__buf_.__large); 22530b57cec5SDimitry Andric else 22540b57cec5SDimitry Andric return reinterpret_cast<const _Tp*>(&__buf_.__small); 22550b57cec5SDimitry Andric } 22560b57cec5SDimitry Andric#endif // _LIBCPP_NO_RTTI 22570b57cec5SDimitry Andric}; 22580b57cec5SDimitry Andric 22595ffd83dbSDimitry Andric#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC) 22605ffd83dbSDimitry Andric 2261*e8d8bef9SDimitry Andricextern "C" void *_Block_copy(const void *); 2262*e8d8bef9SDimitry Andricextern "C" void _Block_release(const void *); 2263*e8d8bef9SDimitry Andric 22645ffd83dbSDimitry Andrictemplate<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes> 22655ffd83dbSDimitry Andricclass __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> 22665ffd83dbSDimitry Andric : public __base<_Rp(_ArgTypes...)> 22675ffd83dbSDimitry Andric{ 22685ffd83dbSDimitry Andric typedef _Rp1(^__block_type)(_ArgTypes1...); 22695ffd83dbSDimitry Andric __block_type __f_; 22705ffd83dbSDimitry Andric 22715ffd83dbSDimitry Andricpublic: 22725ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY 22735ffd83dbSDimitry Andric explicit __func(__block_type const& __f) 2274*e8d8bef9SDimitry Andric : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) 22755ffd83dbSDimitry Andric { } 22765ffd83dbSDimitry Andric 22775ffd83dbSDimitry Andric // [TODO] add && to save on a retain 22785ffd83dbSDimitry Andric 22795ffd83dbSDimitry Andric _LIBCPP_INLINE_VISIBILITY 22805ffd83dbSDimitry Andric explicit __func(__block_type __f, const _Alloc& /* unused */) 2281*e8d8bef9SDimitry Andric : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) 22825ffd83dbSDimitry Andric { } 22835ffd83dbSDimitry Andric 22845ffd83dbSDimitry Andric virtual __base<_Rp(_ArgTypes...)>* __clone() const { 22855ffd83dbSDimitry Andric _LIBCPP_ASSERT(false, 22865ffd83dbSDimitry Andric "Block pointers are just pointers, so they should always fit into " 22875ffd83dbSDimitry Andric "std::function's small buffer optimization. This function should " 22885ffd83dbSDimitry Andric "never be invoked."); 22895ffd83dbSDimitry Andric return nullptr; 22905ffd83dbSDimitry Andric } 22915ffd83dbSDimitry Andric 22925ffd83dbSDimitry Andric virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const { 2293*e8d8bef9SDimitry Andric ::new ((void*)__p) __func(__f_); 22945ffd83dbSDimitry Andric } 22955ffd83dbSDimitry Andric 22965ffd83dbSDimitry Andric virtual void destroy() _NOEXCEPT { 22975ffd83dbSDimitry Andric if (__f_) 2298*e8d8bef9SDimitry Andric _Block_release(__f_); 22995ffd83dbSDimitry Andric __f_ = 0; 23005ffd83dbSDimitry Andric } 23015ffd83dbSDimitry Andric 23025ffd83dbSDimitry Andric virtual void destroy_deallocate() _NOEXCEPT { 23035ffd83dbSDimitry Andric _LIBCPP_ASSERT(false, 23045ffd83dbSDimitry Andric "Block pointers are just pointers, so they should always fit into " 23055ffd83dbSDimitry Andric "std::function's small buffer optimization. This function should " 23065ffd83dbSDimitry Andric "never be invoked."); 23075ffd83dbSDimitry Andric } 23085ffd83dbSDimitry Andric 23095ffd83dbSDimitry Andric virtual _Rp operator()(_ArgTypes&& ... __arg) { 2310*e8d8bef9SDimitry Andric return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...); 23115ffd83dbSDimitry Andric } 23125ffd83dbSDimitry Andric 23135ffd83dbSDimitry Andric#ifndef _LIBCPP_NO_RTTI 23145ffd83dbSDimitry Andric virtual const void* target(type_info const& __ti) const _NOEXCEPT { 23155ffd83dbSDimitry Andric if (__ti == typeid(__func::__block_type)) 23165ffd83dbSDimitry Andric return &__f_; 23175ffd83dbSDimitry Andric return (const void*)nullptr; 23185ffd83dbSDimitry Andric } 23195ffd83dbSDimitry Andric 23205ffd83dbSDimitry Andric virtual const std::type_info& target_type() const _NOEXCEPT { 23215ffd83dbSDimitry Andric return typeid(__func::__block_type); 23225ffd83dbSDimitry Andric } 23235ffd83dbSDimitry Andric#endif // _LIBCPP_NO_RTTI 23245ffd83dbSDimitry Andric}; 23255ffd83dbSDimitry Andric 23265ffd83dbSDimitry Andric#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC 23275ffd83dbSDimitry Andric 23280b57cec5SDimitry Andric} // __function 23290b57cec5SDimitry Andric 23300b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 23310b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> 23320b57cec5SDimitry Andric : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, 23330b57cec5SDimitry Andric public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> 23340b57cec5SDimitry Andric{ 23350b57cec5SDimitry Andric#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION 23360b57cec5SDimitry Andric typedef __function::__value_func<_Rp(_ArgTypes...)> __func; 23370b57cec5SDimitry Andric#else 23380b57cec5SDimitry Andric typedef __function::__policy_func<_Rp(_ArgTypes...)> __func; 23390b57cec5SDimitry Andric#endif 23400b57cec5SDimitry Andric 23410b57cec5SDimitry Andric __func __f_; 23420b57cec5SDimitry Andric 23430b57cec5SDimitry Andric template <class _Fp, bool = _And< 23440b57cec5SDimitry Andric _IsNotSame<__uncvref_t<_Fp>, function>, 23455ffd83dbSDimitry Andric __invokable<_Fp, _ArgTypes...> 23460b57cec5SDimitry Andric >::value> 23470b57cec5SDimitry Andric struct __callable; 23480b57cec5SDimitry Andric template <class _Fp> 23490b57cec5SDimitry Andric struct __callable<_Fp, true> 23500b57cec5SDimitry Andric { 2351*e8d8bef9SDimitry Andric static const bool value = is_void<_Rp>::value || 2352*e8d8bef9SDimitry Andric __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type, 23530b57cec5SDimitry Andric _Rp>::value; 23540b57cec5SDimitry Andric }; 23550b57cec5SDimitry Andric template <class _Fp> 23560b57cec5SDimitry Andric struct __callable<_Fp, false> 23570b57cec5SDimitry Andric { 23580b57cec5SDimitry Andric static const bool value = false; 23590b57cec5SDimitry Andric }; 23600b57cec5SDimitry Andric 23610b57cec5SDimitry Andric template <class _Fp> 23625ffd83dbSDimitry Andric using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type; 23630b57cec5SDimitry Andricpublic: 23640b57cec5SDimitry Andric typedef _Rp result_type; 23650b57cec5SDimitry Andric 23660b57cec5SDimitry Andric // construct/copy/destroy: 23670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23680b57cec5SDimitry Andric function() _NOEXCEPT { } 23690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23700b57cec5SDimitry Andric function(nullptr_t) _NOEXCEPT {} 23710b57cec5SDimitry Andric function(const function&); 23720b57cec5SDimitry Andric function(function&&) _NOEXCEPT; 23735ffd83dbSDimitry Andric template<class _Fp, class = _EnableIfLValueCallable<_Fp>> 23740b57cec5SDimitry Andric function(_Fp); 23750b57cec5SDimitry Andric 23760b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 23770b57cec5SDimitry Andric template<class _Alloc> 23780b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23790b57cec5SDimitry Andric function(allocator_arg_t, const _Alloc&) _NOEXCEPT {} 23800b57cec5SDimitry Andric template<class _Alloc> 23810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23820b57cec5SDimitry Andric function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {} 23830b57cec5SDimitry Andric template<class _Alloc> 23840b57cec5SDimitry Andric function(allocator_arg_t, const _Alloc&, const function&); 23850b57cec5SDimitry Andric template<class _Alloc> 23860b57cec5SDimitry Andric function(allocator_arg_t, const _Alloc&, function&&); 23875ffd83dbSDimitry Andric template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>> 23880b57cec5SDimitry Andric function(allocator_arg_t, const _Alloc& __a, _Fp __f); 23890b57cec5SDimitry Andric#endif 23900b57cec5SDimitry Andric 23910b57cec5SDimitry Andric function& operator=(const function&); 23920b57cec5SDimitry Andric function& operator=(function&&) _NOEXCEPT; 23930b57cec5SDimitry Andric function& operator=(nullptr_t) _NOEXCEPT; 23945ffd83dbSDimitry Andric template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>> 23950b57cec5SDimitry Andric function& operator=(_Fp&&); 23960b57cec5SDimitry Andric 23970b57cec5SDimitry Andric ~function(); 23980b57cec5SDimitry Andric 23990b57cec5SDimitry Andric // function modifiers: 24000b57cec5SDimitry Andric void swap(function&) _NOEXCEPT; 24010b57cec5SDimitry Andric 24020b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 24030b57cec5SDimitry Andric template<class _Fp, class _Alloc> 24040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24050b57cec5SDimitry Andric void assign(_Fp&& __f, const _Alloc& __a) 24060b57cec5SDimitry Andric {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} 24070b57cec5SDimitry Andric#endif 24080b57cec5SDimitry Andric 24090b57cec5SDimitry Andric // function capacity: 24100b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24110b57cec5SDimitry Andric _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { 24120b57cec5SDimitry Andric return static_cast<bool>(__f_); 24130b57cec5SDimitry Andric } 24140b57cec5SDimitry Andric 24150b57cec5SDimitry Andric // deleted overloads close possible hole in the type system 24160b57cec5SDimitry Andric template<class _R2, class... _ArgTypes2> 24170b57cec5SDimitry Andric bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; 24180b57cec5SDimitry Andric template<class _R2, class... _ArgTypes2> 24190b57cec5SDimitry Andric bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; 24200b57cec5SDimitry Andricpublic: 24210b57cec5SDimitry Andric // function invocation: 24220b57cec5SDimitry Andric _Rp operator()(_ArgTypes...) const; 24230b57cec5SDimitry Andric 24240b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 24250b57cec5SDimitry Andric // function target access: 24260b57cec5SDimitry Andric const std::type_info& target_type() const _NOEXCEPT; 24270b57cec5SDimitry Andric template <typename _Tp> _Tp* target() _NOEXCEPT; 24280b57cec5SDimitry Andric template <typename _Tp> const _Tp* target() const _NOEXCEPT; 24290b57cec5SDimitry Andric#endif // _LIBCPP_NO_RTTI 24300b57cec5SDimitry Andric}; 24310b57cec5SDimitry Andric 2432e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 2433e40139ffSDimitry Andrictemplate<class _Rp, class ..._Ap> 2434e40139ffSDimitry Andricfunction(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; 2435e40139ffSDimitry Andric 2436e40139ffSDimitry Andrictemplate<class _Fp> 2437e40139ffSDimitry Andricstruct __strip_signature; 2438e40139ffSDimitry Andric 2439e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2440e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; 2441e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2442e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; 2443e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2444e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; 2445e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2446e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; 2447e40139ffSDimitry Andric 2448e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2449e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; 2450e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2451e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; 2452e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2453e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; 2454e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2455e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; 2456e40139ffSDimitry Andric 2457e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2458e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; 2459e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2460e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; 2461e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2462e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; 2463e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2464e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; 2465e40139ffSDimitry Andric 2466e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2467e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; 2468e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2469e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; 2470e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2471e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; 2472e40139ffSDimitry Andrictemplate<class _Rp, class _Gp, class ..._Ap> 2473e40139ffSDimitry Andricstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; 2474e40139ffSDimitry Andric 2475e40139ffSDimitry Andrictemplate<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type> 2476e40139ffSDimitry Andricfunction(_Fp) -> function<_Stripped>; 2477e40139ffSDimitry Andric#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES 2478e40139ffSDimitry Andric 24790b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 24800b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} 24810b57cec5SDimitry Andric 24820b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 24830b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 24840b57cec5SDimitry Andrictemplate <class _Alloc> 24850b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 24860b57cec5SDimitry Andric const function& __f) : __f_(__f.__f_) {} 24870b57cec5SDimitry Andric#endif 24880b57cec5SDimitry Andric 24890b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 24900b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT 24910b57cec5SDimitry Andric : __f_(_VSTD::move(__f.__f_)) {} 24920b57cec5SDimitry Andric 24930b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 24940b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 24950b57cec5SDimitry Andrictemplate <class _Alloc> 24960b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 24970b57cec5SDimitry Andric function&& __f) 24980b57cec5SDimitry Andric : __f_(_VSTD::move(__f.__f_)) {} 24990b57cec5SDimitry Andric#endif 25000b57cec5SDimitry Andric 25010b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 25020b57cec5SDimitry Andrictemplate <class _Fp, class> 25030b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {} 25040b57cec5SDimitry Andric 25050b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 25060b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 25070b57cec5SDimitry Andrictemplate <class _Fp, class _Alloc, class> 25080b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, 25090b57cec5SDimitry Andric _Fp __f) 25100b57cec5SDimitry Andric : __f_(_VSTD::move(__f), __a) {} 25110b57cec5SDimitry Andric#endif 25120b57cec5SDimitry Andric 25130b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25140b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>& 25150b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::operator=(const function& __f) 25160b57cec5SDimitry Andric{ 25170b57cec5SDimitry Andric function(__f).swap(*this); 25180b57cec5SDimitry Andric return *this; 25190b57cec5SDimitry Andric} 25200b57cec5SDimitry Andric 25210b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25220b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>& 25230b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT 25240b57cec5SDimitry Andric{ 2525*e8d8bef9SDimitry Andric __f_ = _VSTD::move(__f.__f_); 25260b57cec5SDimitry Andric return *this; 25270b57cec5SDimitry Andric} 25280b57cec5SDimitry Andric 25290b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25300b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>& 25310b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT 25320b57cec5SDimitry Andric{ 25330b57cec5SDimitry Andric __f_ = nullptr; 25340b57cec5SDimitry Andric return *this; 25350b57cec5SDimitry Andric} 25360b57cec5SDimitry Andric 25370b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25380b57cec5SDimitry Andrictemplate <class _Fp, class> 25390b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>& 25400b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) 25410b57cec5SDimitry Andric{ 25420b57cec5SDimitry Andric function(_VSTD::forward<_Fp>(__f)).swap(*this); 25430b57cec5SDimitry Andric return *this; 25440b57cec5SDimitry Andric} 25450b57cec5SDimitry Andric 25460b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25470b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::~function() {} 25480b57cec5SDimitry Andric 25490b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25500b57cec5SDimitry Andricvoid 25510b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT 25520b57cec5SDimitry Andric{ 25530b57cec5SDimitry Andric __f_.swap(__f.__f_); 25540b57cec5SDimitry Andric} 25550b57cec5SDimitry Andric 25560b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25570b57cec5SDimitry Andric_Rp 25580b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 25590b57cec5SDimitry Andric{ 25600b57cec5SDimitry Andric return __f_(_VSTD::forward<_ArgTypes>(__arg)...); 25610b57cec5SDimitry Andric} 25620b57cec5SDimitry Andric 25630b57cec5SDimitry Andric#ifndef _LIBCPP_NO_RTTI 25640b57cec5SDimitry Andric 25650b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25660b57cec5SDimitry Andricconst std::type_info& 25670b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 25680b57cec5SDimitry Andric{ 25690b57cec5SDimitry Andric return __f_.target_type(); 25700b57cec5SDimitry Andric} 25710b57cec5SDimitry Andric 25720b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25730b57cec5SDimitry Andrictemplate <typename _Tp> 25740b57cec5SDimitry Andric_Tp* 25750b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT 25760b57cec5SDimitry Andric{ 25770b57cec5SDimitry Andric return (_Tp*)(__f_.template target<_Tp>()); 25780b57cec5SDimitry Andric} 25790b57cec5SDimitry Andric 25800b57cec5SDimitry Andrictemplate<class _Rp, class ..._ArgTypes> 25810b57cec5SDimitry Andrictemplate <typename _Tp> 25820b57cec5SDimitry Andricconst _Tp* 25830b57cec5SDimitry Andricfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 25840b57cec5SDimitry Andric{ 25850b57cec5SDimitry Andric return __f_.template target<_Tp>(); 25860b57cec5SDimitry Andric} 25870b57cec5SDimitry Andric 25880b57cec5SDimitry Andric#endif // _LIBCPP_NO_RTTI 25890b57cec5SDimitry Andric 25900b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 25910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25920b57cec5SDimitry Andricbool 25930b57cec5SDimitry Andricoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 25940b57cec5SDimitry Andric 25950b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 25960b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25970b57cec5SDimitry Andricbool 25980b57cec5SDimitry Andricoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 25990b57cec5SDimitry Andric 26000b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 26010b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26020b57cec5SDimitry Andricbool 26030b57cec5SDimitry Andricoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 26040b57cec5SDimitry Andric 26050b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 26060b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26070b57cec5SDimitry Andricbool 26080b57cec5SDimitry Andricoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 26090b57cec5SDimitry Andric 26100b57cec5SDimitry Andrictemplate <class _Rp, class... _ArgTypes> 26110b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26120b57cec5SDimitry Andricvoid 26130b57cec5SDimitry Andricswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 26140b57cec5SDimitry Andric{return __x.swap(__y);} 26150b57cec5SDimitry Andric 26160b57cec5SDimitry Andric#else // _LIBCPP_CXX03_LANG 26170b57cec5SDimitry Andric 26180b57cec5SDimitry Andric#include <__functional_03> 26190b57cec5SDimitry Andric 26200b57cec5SDimitry Andric#endif 26210b57cec5SDimitry Andric 26220b57cec5SDimitry Andric//////////////////////////////////////////////////////////////////////////////// 26230b57cec5SDimitry Andric// BIND 26240b57cec5SDimitry Andric//============================================================================== 26250b57cec5SDimitry Andric 26260b57cec5SDimitry Andrictemplate<class _Tp> struct __is_bind_expression : public false_type {}; 26270b57cec5SDimitry Andrictemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression 26280b57cec5SDimitry Andric : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 26290b57cec5SDimitry Andric 26300b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 26310b57cec5SDimitry Andrictemplate <class _Tp> 26320b57cec5SDimitry Andric_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; 26330b57cec5SDimitry Andric#endif 26340b57cec5SDimitry Andric 26350b57cec5SDimitry Andrictemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 26360b57cec5SDimitry Andrictemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder 26370b57cec5SDimitry Andric : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 26380b57cec5SDimitry Andric 26390b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 26400b57cec5SDimitry Andrictemplate <class _Tp> 26410b57cec5SDimitry Andric_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; 26420b57cec5SDimitry Andric#endif 26430b57cec5SDimitry Andric 26440b57cec5SDimitry Andricnamespace placeholders 26450b57cec5SDimitry Andric{ 26460b57cec5SDimitry Andric 26470b57cec5SDimitry Andrictemplate <int _Np> struct __ph {}; 26480b57cec5SDimitry Andric 26490b57cec5SDimitry Andric#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 26500b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<1> _1; 26510b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<2> _2; 26520b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<3> _3; 26530b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<4> _4; 26540b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<5> _5; 26550b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<6> _6; 26560b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<7> _7; 26570b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<8> _8; 26580b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<9> _9; 26590b57cec5SDimitry Andric_LIBCPP_FUNC_VIS extern const __ph<10> _10; 26600b57cec5SDimitry Andric#else 26610b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{}; 26620b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{}; 26630b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{}; 26640b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{}; 26650b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{}; 26660b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{}; 26670b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{}; 26680b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{}; 26690b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{}; 26700b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{}; 26710b57cec5SDimitry Andric#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 26720b57cec5SDimitry Andric 26730b57cec5SDimitry Andric} // placeholders 26740b57cec5SDimitry Andric 26750b57cec5SDimitry Andrictemplate<int _Np> 26760b57cec5SDimitry Andricstruct __is_placeholder<placeholders::__ph<_Np> > 26770b57cec5SDimitry Andric : public integral_constant<int, _Np> {}; 26780b57cec5SDimitry Andric 26790b57cec5SDimitry Andric 26800b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 26810b57cec5SDimitry Andric 26820b57cec5SDimitry Andrictemplate <class _Tp, class _Uj> 26830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26840b57cec5SDimitry Andric_Tp& 26850b57cec5SDimitry Andric__mu(reference_wrapper<_Tp> __t, _Uj&) 26860b57cec5SDimitry Andric{ 26870b57cec5SDimitry Andric return __t.get(); 26880b57cec5SDimitry Andric} 26890b57cec5SDimitry Andric 26900b57cec5SDimitry Andrictemplate <class _Ti, class ..._Uj, size_t ..._Indx> 26910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26920b57cec5SDimitry Andrictypename __invoke_of<_Ti&, _Uj...>::type 26930b57cec5SDimitry Andric__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 26940b57cec5SDimitry Andric{ 26950b57cec5SDimitry Andric return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); 26960b57cec5SDimitry Andric} 26970b57cec5SDimitry Andric 26980b57cec5SDimitry Andrictemplate <class _Ti, class ..._Uj> 26990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 27000b57cec5SDimitry Andrictypename _EnableIf 27010b57cec5SDimitry Andric< 27020b57cec5SDimitry Andric is_bind_expression<_Ti>::value, 27030b57cec5SDimitry Andric __invoke_of<_Ti&, _Uj...> 27040b57cec5SDimitry Andric>::type 27050b57cec5SDimitry Andric__mu(_Ti& __ti, tuple<_Uj...>& __uj) 27060b57cec5SDimitry Andric{ 27070b57cec5SDimitry Andric typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 2708*e8d8bef9SDimitry Andric return _VSTD::__mu_expand(__ti, __uj, __indices()); 27090b57cec5SDimitry Andric} 27100b57cec5SDimitry Andric 27110b57cec5SDimitry Andrictemplate <bool IsPh, class _Ti, class _Uj> 27120b57cec5SDimitry Andricstruct __mu_return2 {}; 27130b57cec5SDimitry Andric 27140b57cec5SDimitry Andrictemplate <class _Ti, class _Uj> 27150b57cec5SDimitry Andricstruct __mu_return2<true, _Ti, _Uj> 27160b57cec5SDimitry Andric{ 27170b57cec5SDimitry Andric typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 27180b57cec5SDimitry Andric}; 27190b57cec5SDimitry Andric 27200b57cec5SDimitry Andrictemplate <class _Ti, class _Uj> 27210b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 27220b57cec5SDimitry Andrictypename enable_if 27230b57cec5SDimitry Andric< 27240b57cec5SDimitry Andric 0 < is_placeholder<_Ti>::value, 27250b57cec5SDimitry Andric typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 27260b57cec5SDimitry Andric>::type 27270b57cec5SDimitry Andric__mu(_Ti&, _Uj& __uj) 27280b57cec5SDimitry Andric{ 27290b57cec5SDimitry Andric const size_t _Indx = is_placeholder<_Ti>::value - 1; 27300b57cec5SDimitry Andric return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); 27310b57cec5SDimitry Andric} 27320b57cec5SDimitry Andric 27330b57cec5SDimitry Andrictemplate <class _Ti, class _Uj> 27340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 27350b57cec5SDimitry Andrictypename enable_if 27360b57cec5SDimitry Andric< 27370b57cec5SDimitry Andric !is_bind_expression<_Ti>::value && 27380b57cec5SDimitry Andric is_placeholder<_Ti>::value == 0 && 27390b57cec5SDimitry Andric !__is_reference_wrapper<_Ti>::value, 27400b57cec5SDimitry Andric _Ti& 27410b57cec5SDimitry Andric>::type 27420b57cec5SDimitry Andric__mu(_Ti& __ti, _Uj&) 27430b57cec5SDimitry Andric{ 27440b57cec5SDimitry Andric return __ti; 27450b57cec5SDimitry Andric} 27460b57cec5SDimitry Andric 27470b57cec5SDimitry Andrictemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 27480b57cec5SDimitry Andric class _TupleUj> 27490b57cec5SDimitry Andricstruct __mu_return_impl; 27500b57cec5SDimitry Andric 27510b57cec5SDimitry Andrictemplate <bool _Invokable, class _Ti, class ..._Uj> 27520b57cec5SDimitry Andricstruct __mu_return_invokable // false 27530b57cec5SDimitry Andric{ 27540b57cec5SDimitry Andric typedef __nat type; 27550b57cec5SDimitry Andric}; 27560b57cec5SDimitry Andric 27570b57cec5SDimitry Andrictemplate <class _Ti, class ..._Uj> 27580b57cec5SDimitry Andricstruct __mu_return_invokable<true, _Ti, _Uj...> 27590b57cec5SDimitry Andric{ 27600b57cec5SDimitry Andric typedef typename __invoke_of<_Ti&, _Uj...>::type type; 27610b57cec5SDimitry Andric}; 27620b57cec5SDimitry Andric 27630b57cec5SDimitry Andrictemplate <class _Ti, class ..._Uj> 27640b57cec5SDimitry Andricstruct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > 27650b57cec5SDimitry Andric : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> 27660b57cec5SDimitry Andric{ 27670b57cec5SDimitry Andric}; 27680b57cec5SDimitry Andric 27690b57cec5SDimitry Andrictemplate <class _Ti, class _TupleUj> 27700b57cec5SDimitry Andricstruct __mu_return_impl<_Ti, false, false, true, _TupleUj> 27710b57cec5SDimitry Andric{ 27720b57cec5SDimitry Andric typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 27730b57cec5SDimitry Andric _TupleUj>::type&& type; 27740b57cec5SDimitry Andric}; 27750b57cec5SDimitry Andric 27760b57cec5SDimitry Andrictemplate <class _Ti, class _TupleUj> 27770b57cec5SDimitry Andricstruct __mu_return_impl<_Ti, true, false, false, _TupleUj> 27780b57cec5SDimitry Andric{ 27790b57cec5SDimitry Andric typedef typename _Ti::type& type; 27800b57cec5SDimitry Andric}; 27810b57cec5SDimitry Andric 27820b57cec5SDimitry Andrictemplate <class _Ti, class _TupleUj> 27830b57cec5SDimitry Andricstruct __mu_return_impl<_Ti, false, false, false, _TupleUj> 27840b57cec5SDimitry Andric{ 27850b57cec5SDimitry Andric typedef _Ti& type; 27860b57cec5SDimitry Andric}; 27870b57cec5SDimitry Andric 27880b57cec5SDimitry Andrictemplate <class _Ti, class _TupleUj> 27890b57cec5SDimitry Andricstruct __mu_return 27900b57cec5SDimitry Andric : public __mu_return_impl<_Ti, 27910b57cec5SDimitry Andric __is_reference_wrapper<_Ti>::value, 27920b57cec5SDimitry Andric is_bind_expression<_Ti>::value, 27930b57cec5SDimitry Andric 0 < is_placeholder<_Ti>::value && 27940b57cec5SDimitry Andric is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 27950b57cec5SDimitry Andric _TupleUj> 27960b57cec5SDimitry Andric{ 27970b57cec5SDimitry Andric}; 27980b57cec5SDimitry Andric 27990b57cec5SDimitry Andrictemplate <class _Fp, class _BoundArgs, class _TupleUj> 28000b57cec5SDimitry Andricstruct __is_valid_bind_return 28010b57cec5SDimitry Andric{ 28020b57cec5SDimitry Andric static const bool value = false; 28030b57cec5SDimitry Andric}; 28040b57cec5SDimitry Andric 28050b57cec5SDimitry Andrictemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 28060b57cec5SDimitry Andricstruct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 28070b57cec5SDimitry Andric{ 28080b57cec5SDimitry Andric static const bool value = __invokable<_Fp, 28090b57cec5SDimitry Andric typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 28100b57cec5SDimitry Andric}; 28110b57cec5SDimitry Andric 28120b57cec5SDimitry Andrictemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 28130b57cec5SDimitry Andricstruct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 28140b57cec5SDimitry Andric{ 28150b57cec5SDimitry Andric static const bool value = __invokable<_Fp, 28160b57cec5SDimitry Andric typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 28170b57cec5SDimitry Andric}; 28180b57cec5SDimitry Andric 28190b57cec5SDimitry Andrictemplate <class _Fp, class _BoundArgs, class _TupleUj, 28200b57cec5SDimitry Andric bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 28210b57cec5SDimitry Andricstruct __bind_return; 28220b57cec5SDimitry Andric 28230b57cec5SDimitry Andrictemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 28240b57cec5SDimitry Andricstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> 28250b57cec5SDimitry Andric{ 28260b57cec5SDimitry Andric typedef typename __invoke_of 28270b57cec5SDimitry Andric < 28280b57cec5SDimitry Andric _Fp&, 28290b57cec5SDimitry Andric typename __mu_return 28300b57cec5SDimitry Andric < 28310b57cec5SDimitry Andric _BoundArgs, 28320b57cec5SDimitry Andric _TupleUj 28330b57cec5SDimitry Andric >::type... 28340b57cec5SDimitry Andric >::type type; 28350b57cec5SDimitry Andric}; 28360b57cec5SDimitry Andric 28370b57cec5SDimitry Andrictemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 28380b57cec5SDimitry Andricstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 28390b57cec5SDimitry Andric{ 28400b57cec5SDimitry Andric typedef typename __invoke_of 28410b57cec5SDimitry Andric < 28420b57cec5SDimitry Andric _Fp&, 28430b57cec5SDimitry Andric typename __mu_return 28440b57cec5SDimitry Andric < 28450b57cec5SDimitry Andric const _BoundArgs, 28460b57cec5SDimitry Andric _TupleUj 28470b57cec5SDimitry Andric >::type... 28480b57cec5SDimitry Andric >::type type; 28490b57cec5SDimitry Andric}; 28500b57cec5SDimitry Andric 28510b57cec5SDimitry Andrictemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 28520b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 28530b57cec5SDimitry Andrictypename __bind_return<_Fp, _BoundArgs, _Args>::type 28540b57cec5SDimitry Andric__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 28550b57cec5SDimitry Andric _Args&& __args) 28560b57cec5SDimitry Andric{ 28570b57cec5SDimitry Andric return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...); 28580b57cec5SDimitry Andric} 28590b57cec5SDimitry Andric 28600b57cec5SDimitry Andrictemplate<class _Fp, class ..._BoundArgs> 28610b57cec5SDimitry Andricclass __bind 28620b57cec5SDimitry Andric : public __weak_result_type<typename decay<_Fp>::type> 28630b57cec5SDimitry Andric{ 28640b57cec5SDimitry Andricprotected: 28650b57cec5SDimitry Andric typedef typename decay<_Fp>::type _Fd; 28660b57cec5SDimitry Andric typedef tuple<typename decay<_BoundArgs>::type...> _Td; 28670b57cec5SDimitry Andricprivate: 28680b57cec5SDimitry Andric _Fd __f_; 28690b57cec5SDimitry Andric _Td __bound_args_; 28700b57cec5SDimitry Andric 28710b57cec5SDimitry Andric typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 28720b57cec5SDimitry Andricpublic: 28730b57cec5SDimitry Andric template <class _Gp, class ..._BA, 28740b57cec5SDimitry Andric class = typename enable_if 28750b57cec5SDimitry Andric < 28760b57cec5SDimitry Andric is_constructible<_Fd, _Gp>::value && 28770b57cec5SDimitry Andric !is_same<typename remove_reference<_Gp>::type, 28780b57cec5SDimitry Andric __bind>::value 28790b57cec5SDimitry Andric >::type> 2880*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 28810b57cec5SDimitry Andric explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 28820b57cec5SDimitry Andric : __f_(_VSTD::forward<_Gp>(__f)), 28830b57cec5SDimitry Andric __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 28840b57cec5SDimitry Andric 28850b57cec5SDimitry Andric template <class ..._Args> 2886*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 28870b57cec5SDimitry Andric typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 28880b57cec5SDimitry Andric operator()(_Args&& ...__args) 28890b57cec5SDimitry Andric { 28900b57cec5SDimitry Andric return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), 28910b57cec5SDimitry Andric tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 28920b57cec5SDimitry Andric } 28930b57cec5SDimitry Andric 28940b57cec5SDimitry Andric template <class ..._Args> 2895*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 28960b57cec5SDimitry Andric typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 28970b57cec5SDimitry Andric operator()(_Args&& ...__args) const 28980b57cec5SDimitry Andric { 28990b57cec5SDimitry Andric return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), 29000b57cec5SDimitry Andric tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 29010b57cec5SDimitry Andric } 29020b57cec5SDimitry Andric}; 29030b57cec5SDimitry Andric 29040b57cec5SDimitry Andrictemplate<class _Fp, class ..._BoundArgs> 29050b57cec5SDimitry Andricstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 29060b57cec5SDimitry Andric 29070b57cec5SDimitry Andrictemplate<class _Rp, class _Fp, class ..._BoundArgs> 29080b57cec5SDimitry Andricclass __bind_r 29090b57cec5SDimitry Andric : public __bind<_Fp, _BoundArgs...> 29100b57cec5SDimitry Andric{ 29110b57cec5SDimitry Andric typedef __bind<_Fp, _BoundArgs...> base; 29120b57cec5SDimitry Andric typedef typename base::_Fd _Fd; 29130b57cec5SDimitry Andric typedef typename base::_Td _Td; 29140b57cec5SDimitry Andricpublic: 29150b57cec5SDimitry Andric typedef _Rp result_type; 29160b57cec5SDimitry Andric 29170b57cec5SDimitry Andric 29180b57cec5SDimitry Andric template <class _Gp, class ..._BA, 29190b57cec5SDimitry Andric class = typename enable_if 29200b57cec5SDimitry Andric < 29210b57cec5SDimitry Andric is_constructible<_Fd, _Gp>::value && 29220b57cec5SDimitry Andric !is_same<typename remove_reference<_Gp>::type, 29230b57cec5SDimitry Andric __bind_r>::value 29240b57cec5SDimitry Andric >::type> 2925*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 29260b57cec5SDimitry Andric explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 29270b57cec5SDimitry Andric : base(_VSTD::forward<_Gp>(__f), 29280b57cec5SDimitry Andric _VSTD::forward<_BA>(__bound_args)...) {} 29290b57cec5SDimitry Andric 29300b57cec5SDimitry Andric template <class ..._Args> 2931*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 29320b57cec5SDimitry Andric typename enable_if 29330b57cec5SDimitry Andric < 29340b57cec5SDimitry Andric is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, 29350b57cec5SDimitry Andric result_type>::value || is_void<_Rp>::value, 29360b57cec5SDimitry Andric result_type 29370b57cec5SDimitry Andric >::type 29380b57cec5SDimitry Andric operator()(_Args&& ...__args) 29390b57cec5SDimitry Andric { 29400b57cec5SDimitry Andric typedef __invoke_void_return_wrapper<_Rp> _Invoker; 29410b57cec5SDimitry Andric return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); 29420b57cec5SDimitry Andric } 29430b57cec5SDimitry Andric 29440b57cec5SDimitry Andric template <class ..._Args> 2945*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 29460b57cec5SDimitry Andric typename enable_if 29470b57cec5SDimitry Andric < 29480b57cec5SDimitry Andric is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 29490b57cec5SDimitry Andric result_type>::value || is_void<_Rp>::value, 29500b57cec5SDimitry Andric result_type 29510b57cec5SDimitry Andric >::type 29520b57cec5SDimitry Andric operator()(_Args&& ...__args) const 29530b57cec5SDimitry Andric { 29540b57cec5SDimitry Andric typedef __invoke_void_return_wrapper<_Rp> _Invoker; 29550b57cec5SDimitry Andric return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); 29560b57cec5SDimitry Andric } 29570b57cec5SDimitry Andric}; 29580b57cec5SDimitry Andric 29590b57cec5SDimitry Andrictemplate<class _Rp, class _Fp, class ..._BoundArgs> 29600b57cec5SDimitry Andricstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 29610b57cec5SDimitry Andric 29620b57cec5SDimitry Andrictemplate<class _Fp, class ..._BoundArgs> 2963*e8d8bef9SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 29640b57cec5SDimitry Andric__bind<_Fp, _BoundArgs...> 29650b57cec5SDimitry Andricbind(_Fp&& __f, _BoundArgs&&... __bound_args) 29660b57cec5SDimitry Andric{ 29670b57cec5SDimitry Andric typedef __bind<_Fp, _BoundArgs...> type; 29680b57cec5SDimitry Andric return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 29690b57cec5SDimitry Andric} 29700b57cec5SDimitry Andric 29710b57cec5SDimitry Andrictemplate<class _Rp, class _Fp, class ..._BoundArgs> 2972*e8d8bef9SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 29730b57cec5SDimitry Andric__bind_r<_Rp, _Fp, _BoundArgs...> 29740b57cec5SDimitry Andricbind(_Fp&& __f, _BoundArgs&&... __bound_args) 29750b57cec5SDimitry Andric{ 29760b57cec5SDimitry Andric typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 29770b57cec5SDimitry Andric return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 29780b57cec5SDimitry Andric} 29790b57cec5SDimitry Andric 29800b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 29810b57cec5SDimitry Andric 29820b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 29830b57cec5SDimitry Andric 29840b57cec5SDimitry Andrictemplate <class _Fn, class ..._Args> 2985*e8d8bef9SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 invoke_result_t<_Fn, _Args...> 29860b57cec5SDimitry Andricinvoke(_Fn&& __f, _Args&&... __args) 29870b57cec5SDimitry Andric noexcept(is_nothrow_invocable_v<_Fn, _Args...>) 29880b57cec5SDimitry Andric{ 29890b57cec5SDimitry Andric return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); 29900b57cec5SDimitry Andric} 29910b57cec5SDimitry Andric 29920b57cec5SDimitry Andrictemplate <class _DecayFunc> 29930b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __not_fn_imp { 29940b57cec5SDimitry Andric _DecayFunc __fd; 29950b57cec5SDimitry Andric 29960b57cec5SDimitry Andricpublic: 29970b57cec5SDimitry Andric __not_fn_imp() = delete; 29980b57cec5SDimitry Andric 29990b57cec5SDimitry Andric template <class ..._Args> 3000*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30010b57cec5SDimitry Andric auto operator()(_Args&& ...__args) & 30020b57cec5SDimitry Andric noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 30030b57cec5SDimitry Andric -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 30040b57cec5SDimitry Andric { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 30050b57cec5SDimitry Andric 30060b57cec5SDimitry Andric template <class ..._Args> 3007*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30080b57cec5SDimitry Andric auto operator()(_Args&& ...__args) && 30090b57cec5SDimitry Andric noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 30100b57cec5SDimitry Andric -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 30110b57cec5SDimitry Andric { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 30120b57cec5SDimitry Andric 30130b57cec5SDimitry Andric template <class ..._Args> 3014*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30150b57cec5SDimitry Andric auto operator()(_Args&& ...__args) const& 30160b57cec5SDimitry Andric noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 30170b57cec5SDimitry Andric -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 30180b57cec5SDimitry Andric { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 30190b57cec5SDimitry Andric 30200b57cec5SDimitry Andric 30210b57cec5SDimitry Andric template <class ..._Args> 3022*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30230b57cec5SDimitry Andric auto operator()(_Args&& ...__args) const&& 30240b57cec5SDimitry Andric noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 30250b57cec5SDimitry Andric -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 30260b57cec5SDimitry Andric { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 30270b57cec5SDimitry Andric 30280b57cec5SDimitry Andricprivate: 30290b57cec5SDimitry Andric template <class _RawFunc, 30300b57cec5SDimitry Andric class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> 3031*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30320b57cec5SDimitry Andric explicit __not_fn_imp(_RawFunc&& __rf) 30330b57cec5SDimitry Andric : __fd(_VSTD::forward<_RawFunc>(__rf)) {} 30340b57cec5SDimitry Andric 30350b57cec5SDimitry Andric template <class _RawFunc> 3036*e8d8bef9SDimitry Andric friend inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30370b57cec5SDimitry Andric __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); 30380b57cec5SDimitry Andric}; 30390b57cec5SDimitry Andric 30400b57cec5SDimitry Andrictemplate <class _RawFunc> 3041*e8d8bef9SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30420b57cec5SDimitry Andric__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { 30430b57cec5SDimitry Andric return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); 30440b57cec5SDimitry Andric} 30450b57cec5SDimitry Andric 30460b57cec5SDimitry Andric#endif 30470b57cec5SDimitry Andric 30480b57cec5SDimitry Andric// struct hash<T*> in <memory> 30490b57cec5SDimitry Andric 30500b57cec5SDimitry Andrictemplate <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> 30510b57cec5SDimitry Andricpair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11 30520b57cec5SDimitry Andric__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, 30530b57cec5SDimitry Andric _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, 30540b57cec5SDimitry Andric forward_iterator_tag, forward_iterator_tag) 30550b57cec5SDimitry Andric{ 30560b57cec5SDimitry Andric if (__first2 == __last2) 30575ffd83dbSDimitry Andric return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence 30580b57cec5SDimitry Andric while (true) 30590b57cec5SDimitry Andric { 30600b57cec5SDimitry Andric // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks 30610b57cec5SDimitry Andric while (true) 30620b57cec5SDimitry Andric { 30630b57cec5SDimitry Andric if (__first1 == __last1) // return __last1 if no element matches *__first2 30645ffd83dbSDimitry Andric return _VSTD::make_pair(__last1, __last1); 30650b57cec5SDimitry Andric if (__pred(*__first1, *__first2)) 30660b57cec5SDimitry Andric break; 30670b57cec5SDimitry Andric ++__first1; 30680b57cec5SDimitry Andric } 30690b57cec5SDimitry Andric // *__first1 matches *__first2, now match elements after here 30700b57cec5SDimitry Andric _ForwardIterator1 __m1 = __first1; 30710b57cec5SDimitry Andric _ForwardIterator2 __m2 = __first2; 30720b57cec5SDimitry Andric while (true) 30730b57cec5SDimitry Andric { 30740b57cec5SDimitry Andric if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) 30755ffd83dbSDimitry Andric return _VSTD::make_pair(__first1, __m1); 30760b57cec5SDimitry Andric if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found 30775ffd83dbSDimitry Andric return _VSTD::make_pair(__last1, __last1); 30780b57cec5SDimitry Andric if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 30790b57cec5SDimitry Andric { 30800b57cec5SDimitry Andric ++__first1; 30810b57cec5SDimitry Andric break; 30820b57cec5SDimitry Andric } // else there is a match, check next elements 30830b57cec5SDimitry Andric } 30840b57cec5SDimitry Andric } 30850b57cec5SDimitry Andric} 30860b57cec5SDimitry Andric 30870b57cec5SDimitry Andrictemplate <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> 30880b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 30890b57cec5SDimitry Andricpair<_RandomAccessIterator1, _RandomAccessIterator1> 30900b57cec5SDimitry Andric__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, 30910b57cec5SDimitry Andric _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, 30920b57cec5SDimitry Andric random_access_iterator_tag, random_access_iterator_tag) 30930b57cec5SDimitry Andric{ 30940b57cec5SDimitry Andric typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; 30950b57cec5SDimitry Andric typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; 30960b57cec5SDimitry Andric // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern 30970b57cec5SDimitry Andric const _D2 __len2 = __last2 - __first2; 30980b57cec5SDimitry Andric if (__len2 == 0) 30995ffd83dbSDimitry Andric return _VSTD::make_pair(__first1, __first1); 31000b57cec5SDimitry Andric const _D1 __len1 = __last1 - __first1; 31010b57cec5SDimitry Andric if (__len1 < __len2) 31025ffd83dbSDimitry Andric return _VSTD::make_pair(__last1, __last1); 31030b57cec5SDimitry Andric const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here 31040b57cec5SDimitry Andric 31050b57cec5SDimitry Andric while (true) 31060b57cec5SDimitry Andric { 31070b57cec5SDimitry Andric while (true) 31080b57cec5SDimitry Andric { 31090b57cec5SDimitry Andric if (__first1 == __s) 31105ffd83dbSDimitry Andric return _VSTD::make_pair(__last1, __last1); 31110b57cec5SDimitry Andric if (__pred(*__first1, *__first2)) 31120b57cec5SDimitry Andric break; 31130b57cec5SDimitry Andric ++__first1; 31140b57cec5SDimitry Andric } 31150b57cec5SDimitry Andric 31160b57cec5SDimitry Andric _RandomAccessIterator1 __m1 = __first1; 31170b57cec5SDimitry Andric _RandomAccessIterator2 __m2 = __first2; 31180b57cec5SDimitry Andric while (true) 31190b57cec5SDimitry Andric { 31200b57cec5SDimitry Andric if (++__m2 == __last2) 31215ffd83dbSDimitry Andric return _VSTD::make_pair(__first1, __first1 + __len2); 31220b57cec5SDimitry Andric ++__m1; // no need to check range on __m1 because __s guarantees we have enough source 31230b57cec5SDimitry Andric if (!__pred(*__m1, *__m2)) 31240b57cec5SDimitry Andric { 31250b57cec5SDimitry Andric ++__first1; 31260b57cec5SDimitry Andric break; 31270b57cec5SDimitry Andric } 31280b57cec5SDimitry Andric } 31290b57cec5SDimitry Andric } 31300b57cec5SDimitry Andric} 31310b57cec5SDimitry Andric 31320b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 31330b57cec5SDimitry Andric 31340b57cec5SDimitry Andric// default searcher 31350b57cec5SDimitry Andrictemplate<class _ForwardIterator, class _BinaryPredicate = equal_to<>> 31360b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS default_searcher { 31370b57cec5SDimitry Andricpublic: 3138*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 31390b57cec5SDimitry Andric default_searcher(_ForwardIterator __f, _ForwardIterator __l, 31400b57cec5SDimitry Andric _BinaryPredicate __p = _BinaryPredicate()) 31410b57cec5SDimitry Andric : __first_(__f), __last_(__l), __pred_(__p) {} 31420b57cec5SDimitry Andric 31430b57cec5SDimitry Andric template <typename _ForwardIterator2> 3144*e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 31450b57cec5SDimitry Andric pair<_ForwardIterator2, _ForwardIterator2> 31460b57cec5SDimitry Andric operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const 31470b57cec5SDimitry Andric { 31480b57cec5SDimitry Andric return _VSTD::__search(__f, __l, __first_, __last_, __pred_, 31490b57cec5SDimitry Andric typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(), 31500b57cec5SDimitry Andric typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); 31510b57cec5SDimitry Andric } 31520b57cec5SDimitry Andric 31530b57cec5SDimitry Andricprivate: 31540b57cec5SDimitry Andric _ForwardIterator __first_; 31550b57cec5SDimitry Andric _ForwardIterator __last_; 31560b57cec5SDimitry Andric _BinaryPredicate __pred_; 31570b57cec5SDimitry Andric }; 31580b57cec5SDimitry Andric 31590b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 14 31600b57cec5SDimitry Andric 31610b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 31620b57cec5SDimitry Andrictemplate <class _Tp> 31630b57cec5SDimitry Andricusing unwrap_reference_t = typename unwrap_reference<_Tp>::type; 31640b57cec5SDimitry Andric 31650b57cec5SDimitry Andrictemplate <class _Tp> 31660b57cec5SDimitry Andricusing unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type; 31670b57cec5SDimitry Andric#endif // > C++17 31680b57cec5SDimitry Andric 31690b57cec5SDimitry Andrictemplate <class _Container, class _Predicate> 31705ffd83dbSDimitry Andricinline typename _Container::size_type 31715ffd83dbSDimitry Andric__libcpp_erase_if_container(_Container& __c, _Predicate __pred) { 31725ffd83dbSDimitry Andric typename _Container::size_type __old_size = __c.size(); 31735ffd83dbSDimitry Andric 31745ffd83dbSDimitry Andric const typename _Container::iterator __last = __c.end(); 31755ffd83dbSDimitry Andric for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { 31760b57cec5SDimitry Andric if (__pred(*__iter)) 31770b57cec5SDimitry Andric __iter = __c.erase(__iter); 31780b57cec5SDimitry Andric else 31790b57cec5SDimitry Andric ++__iter; 31800b57cec5SDimitry Andric } 31815ffd83dbSDimitry Andric 31825ffd83dbSDimitry Andric return __old_size - __c.size(); 31830b57cec5SDimitry Andric} 31840b57cec5SDimitry Andric 31850b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 31860b57cec5SDimitry Andric 31870b57cec5SDimitry Andric#endif // _LIBCPP_FUNCTIONAL 3188